Compare commits

..

No commits in common. "072536a04c94710f4ed3bfd0952dea3330b1f4ff" and "390744abe1dfe88b6ceeee595e1aaddc569881d9" have entirely different histories.

5 changed files with 21 additions and 61 deletions

View File

@ -1,28 +1,3 @@
# Uptime Status
Simple status page for server uptime.
## Deployment
Init codebase
```
git clone https://github.com/clerie/uptime-status.git
cd uptime-status/
virtualenv -p python3 ENV
cd ..
```
Create `config.cfg` with the following contents and edit values for your needs:
```
PROMETHEUS_API_BASE="http://[::1]:9090"
```
Starten und updaten lässt sich die Flask-App folgendermaßen:
```
cd uptime-status/
git pull
source ENV/bin/activate
pip install -r requirements.txt
UPTIMESTATUS_SETTINGS=/path/to/config.cfg gunicorn uptimestatus:app
deactivate
```

6
app.py
View File

@ -1,6 +0,0 @@
#!/usr/bin/env python3
from uptimestatus import app
if __name__ == "__main__":
app.run(debug=True)

View File

@ -1,13 +1,3 @@
#!/usr/bin/env python3
from flask import Flask
import os
app = Flask(__name__)
app.config["PROMETHEUS_API_BASE"] = "https://[::1]:9090"
if "UPTIMESTATUS_SETTINGS" in os.environ:
app.config.from_envvar('UPTIMESTATUS_SETTINGS')
from .views import app

View File

@ -1,15 +0,0 @@
#!/usr/bin/env python3
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"]],
}

View File

@ -1,15 +1,31 @@
#!/usr/bin/env python3
from . import app
from .utils import process_instance
from flask import render_template
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(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")
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()