Configure settings by config file

This commit is contained in:
clerie 2021-05-15 14:40:53 +02:00
parent 5039be644d
commit fe09b75db9
3 changed files with 28 additions and 1 deletions

View File

@ -1,3 +1,28 @@
# 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
```

View File

@ -4,4 +4,6 @@ from flask import Flask
app = Flask(__name__)
app.config.from_envvar('UPTIMESTATUS_SETTINGS')
from .views import app

View File

@ -9,7 +9,7 @@ import requests
@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")
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")
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)