Skip to content

Instantly share code, notes, and snippets.

@SkaveRat
Last active June 19, 2024 11:53
Show Gist options
  • Save SkaveRat/b496de421f7f7a9f4a98835a526b44e7 to your computer and use it in GitHub Desktop.
Save SkaveRat/b496de421f7f7a9f4a98835a526b44e7 to your computer and use it in GitHub Desktop.
A simple exporter that exports Pegelonline to prometheus
from prometheus_client import Gauge, start_wsgi_server, make_wsgi_app
from wsgiref.simple_server import make_server
import requests
# This is a prometheus exporter for german river water level monitoring.
# Used API: https://pegelonline.wsv.de/webservice/dokuRestapi
# Set the uuid of the station you want to monitor. Uuid can be found via the "stations.json" of the API.
# TODO: Loop over all stations and feed them into prometheus
# Licence: WTFPL
station = "DÜSSELDORF"
uuid = "593647aa-9fea-43ec-a7d6-6476a76ae868"
url = "https://pegelonline.wsv.de/webservices/rest-api/v2/stations/%s/W/measurements.json?start=PT15M" % (uuid)
g = Gauge('pegelonline_level_meters', 'Pegelstand Deutschland', ['uuid', 'station'])
g.labels(uuid, station).set_function(lambda: process_request())
def process_request():
r = requests.get(url=url)
if r.ok:
data = r.json()
print(data)
if len(data) > 0:
return "{:.2f}".format(data[0]['value'] / 100)
return None
if __name__ == '__main__':
# Start up the server to expose the metrics.
app = make_wsgi_app()
httpd = make_server('', 8888, app)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment