Add software

This commit is contained in:
clerie 2021-05-12 21:50:43 +02:00
parent 185a79a933
commit 9aaf2b0b7e
3 changed files with 139 additions and 0 deletions

76
static/status.css Normal file
View File

@ -0,0 +1,76 @@
:root {
--us-ok: #34d058;
--us-warning: #fff432;
--us-critical: #FF3D33;
--us-gray: #d8d8d8;
font-family: Roboto, Arial, sans-serif;
font-weight: 300;
}
.container {
width: calc(100% - 1em);
max-width: 750px;
margin-left: auto;
margin-right: auto;
padding-left: 0.5em;
padding-right: 0.5em;
}
.service {
display: flex;
width: 100%;
margin-top: 1em;
margin-bottom: 1em;
}
.service-name {
width: 30%;
}
.service-status {
width: 70%;
}
.status-bar {
display: flex;
height: 2em;
width: 100%;
}
.status-bar .status-cell {
background-color: var(--us-gray);
height: 100%;
width: 100%;
margin-left: 1px;
margin-right: 1px;
border-radius: 2px;
}
.status-bar .status-cell.ok {
background-color: var(--us-ok);
}
.status-bar .status-cell.warning {
background-color: var(--us-warning);
}
.status-bar .status-cell.critical {
background-color: var(--us-critical);
}
header {
margin-top: 5em;
margin-bottom: 5em;
}
header h1 {
font-size: 6rem;
font-weight: 300;
line-height: 1.2;
}
footer {
margin-top: 3em;
margin-bottom: 3em;
}

32
templates/status.html Normal file
View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Uptime Status</title>
<link rel="stylesheet" href="/static/status.css">
</head>
<body>
<header class="container">
<center><h1 class="display1">Uptime Status</h1></center>
</header>
<section class="container">
{% for metric in metrics %}
<div class="service">
<div class="service-name">
{{ metric.name }}
</div>
<div class="service-status">
<div class="status-bar">
{% for value in metric.i %}
<div class="status-cell {{ value.status}}"></div>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</section>
<footer class="container">
<center>Uptime Status</center>
</footer>
</body>
</html>

31
uptime-status.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
from flask import Flask, render_template
import json
import requests
app = Flask(__name__)
def ratio_to_status(ratio):
if ratio > 0.99:
return "ok"
elif ratio > 0.8:
return "warning"
else:
return "critical"
def process_instance(instance):
return {
"name": instance["metric"]["instance"].split(".")[0],
"i": [{"status": "unknown", "ratio": None} for i in range(56 - len(instance["values"]))] + [{"status": ratio_to_status(float(i[1])), "ratio": float(i[1])} for i in instance["values"]],
}
@app.route("/")
def status():
r = requests.get("https://prometheus.monitoring.clerie.de/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")
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)
if __name__ == "__main__":
app.run()