Skip to content

Instantly share code, notes, and snippets.

@shaposhnikoff
Created November 19, 2023 16:14
Show Gist options
  • Save shaposhnikoff/d742ae8f04ecf53a5a5c57a1f2a35767 to your computer and use it in GitHub Desktop.
Save shaposhnikoff/d742ae8f04ecf53a5a5c57a1f2a35767 to your computer and use it in GitHub Desktop.
NBUStatService Prometheus Currency Exporter
import sys
import time
from prometheus_client import start_http_server, Gauge
import requests,json
nbu_api_endpoint = "https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json"
date = time.strftime("%Y-%m-%d")
for item in json.loads(requests.get(nbu_api_endpoint).text):
globals()[item['cc']] = Gauge(item['cc'], "currency rate ", ["date","currency_name"])
globals()[item['cc']].labels(date = time.strftime("%Y-%m-%d"), currency_name = item['cc']).set(item['rate'])
if __name__ == '__main__':
start_http_server(8000)
while True:
time.sleep(60*60*24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment