Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed url format for better prometheus integration #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ Work in progress
`config` contains what OIDs to scrape and how to process them. It initially
supports enough for the standard interface stats.

Run `snmp_exporter.py`, and then visit http://localhost:9116/?address=1.2.3.4
Run `snmp_exporter.py`, and then visit http://localhost:9116/1.2.3.4
where 1.2.3.4 is the IP of the SNMP device to get metrics.

### Prometheus config

- job_name: 'switch123'
scrape_interval: 10s
metrics_path: '192.168.1.123'
target_groups:
- targets: ['snmp_exporter_server:9116']


## Design

There are two components. An exporter that does the actual scraping,
Expand Down
9 changes: 2 additions & 7 deletions snmp_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ class ForkingHTTPServer(ForkingMixIn, HTTPServer):

class SnmpExporterHandler(BaseHTTPRequestHandler):
def do_GET(self):
params = urlparse.parse_qs(urlparse.urlparse(self.path).query)
if 'address' not in params:
self.send_response(400)
self.end_headers()
self.wfile.write("Missing 'address' from parameters")
return
ip = self.path[1:]
config = yaml.safe_load(open('config'))
output = collect_snmp(config, params['address'][0])
output = collect_snmp(config, ip)
self.send_response(200)
self.send_header('Content-Type', CONTENT_TYPE_LATEST)
self.end_headers()
Expand Down