uptime-status/uptimestatus/views.py

16 lines
576 B
Python
Raw Normal View History

2021-05-12 21:50:43 +02:00
#!/usr/bin/env python3
2021-05-15 14:31:07 +02:00
from . import app
from .utils import process_instance
from flask import render_template
2021-05-12 21:50:43 +02:00
import json
import requests
@app.route("/")
def status():
2021-05-15 14:40:53 +02:00
r = requests.get(app.config["PROMETHEUS_API_BASE"] + "/api/v1/query?query=%28sum_over_time%28up%7Bjob%3D%22node-exporter%22%7D%5B6h%5D%29+%2F+count_over_time%28up%7Bjob%3D%22node-exporter%22%7D%5B6h%5D%29%29%5B14d%3A6h%5D")
2021-05-12 21:50:43 +02:00
j = json.loads(r.text)
metrics = sorted(map(process_instance, j["data"]["result"]), key=lambda m: m["name"])
return render_template("status.html", metrics=metrics)