You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
import time
|
|
import json
|
|
|
|
import requests
|
|
import prometheus_client as pc
|
|
|
|
|
|
class CoronaExporter:
|
|
def __init__(self):
|
|
self.cases7_per_100k = pc.Gauge('cases7_per_100k', 'Faelle der letzten 7 Tage/100.000 EW', ['county'])
|
|
self.cases = pc.Gauge('cases', 'Anzahl Faelle', ['county'])
|
|
self.deaths = pc.Gauge('deaths', 'Anzahl Todesfaelle', ['county'])
|
|
self.death_rate = pc.Gauge('death_rate', 'Sterberate', ['county'])
|
|
self.cases_per_population = pc.Gauge('cases_per_population', 'Betroffenenrate', ['county'])
|
|
self.cases7_bl_per_100k = pc.Gauge('cases7_bl_per_100k', 'Bundeslandweite Faelle der letzten 7 Tage/100.000 EW', ['county'])
|
|
|
|
def get_metrics(self):
|
|
r = requests.get('https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=*&returnGeometry=false&outSR=4326&f=json')
|
|
j = json.loads(r.text)
|
|
|
|
for lk in j['features']:
|
|
name = lk['attributes']['county']
|
|
|
|
self.cases7_per_100k.labels(county=name).set(lk['attributes']['cases7_per_100k'])
|
|
self.cases.labels(county=name).set(lk['attributes']['cases'])
|
|
self.deaths.labels(county=name).set(lk['attributes']['deaths'])
|
|
self.death_rate.labels(county=name).set(lk['attributes']['death_rate'])
|
|
self.cases_per_population.labels(county=name).set(lk['attributes']['cases_per_population'])
|
|
self.cases7_bl_per_100k.labels(county=name).set(lk['attributes']['cases7_bl_per_100k'])
|
|
|
|
|
|
def run(self):
|
|
pc.start_wsgi_server(9001)
|
|
|
|
while True:
|
|
self.get_metrics()
|
|
time.sleep(120)
|
|
|
|
if __name__ == "__main__":
|
|
c = CoronaExporter()
|
|
c.run()
|