add healthcheck

This commit is contained in:
Marco Andronaco 2023-08-09 02:30:01 +02:00
parent 4645c29880
commit 672f267e41
3 changed files with 15 additions and 1 deletions

View File

@ -2,7 +2,8 @@
tests
.dockerignore
.git*
config.json
config.*
docker-compose.yaml
Dockerfile
poetry.lock
pyproject.toml

View File

@ -8,3 +8,8 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${PWD}/config.json:/app/config.json:ro
healthcheck:
test: wget -nv --tries=1 --spider http://localhost:1111/stats || exit 1
interval: 30s
timeout: 5s
retries: 2

View File

@ -4,8 +4,11 @@ from flask import request, redirect, render_template
from docker_status import app
from docker_status.my_docker import update_status
last_updated = datetime.now()
@app.route('/', methods=['GET', 'POST'])
def route_index():
last_updated = datetime.now()
services = update_status()
for name, service in services.items():
containers = service["containers"]
@ -14,3 +17,8 @@ def route_index():
if request.method == 'GET':
return render_template("index.html", services=services)
return json.dumps(services)
@app.route('/stats')
def route_stats():
return json.dumps({ "last_updated": last_updated.strftime("%Y-%m-%dT%H:%M:%SZ") })