Skip to content

Instantly share code, notes, and snippets.

@banteg
Created December 23, 2017 23:56
Show Gist options
  • Save banteg/685f6b802b88005c9dd2b01a3374173b to your computer and use it in GitHub Desktop.
Save banteg/685f6b802b88005c9dd2b01a3374173b to your computer and use it in GitHub Desktop.
import puresnmp
from prometheus_client.core import REGISTRY, GaugeMetricFamily
from prometheus_client import start_http_server
class AirPortExporter:
def collect(self):
in_bytes = puresnmp.get('10.0.1.1', 'public', '1.3.6.1.2.1.2.2.1.10.1')
out_bytes = puresnmp.get('10.0.1.1', 'public', '1.3.6.1.2.1.2.2.1.16.1')
metric = GaugeMetricFamily('airport', 'airport', labels=['direction'])
print('in', in_bytes, 'out', out_bytes)
metric.add_metric(['in'], in_bytes)
metric.add_metric(['out'], out_bytes)
yield metric
if __name__ == '__main__':
REGISTRY.register(AirPortExporter())
start_http_server(9116)
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment