This commit is contained in:
LORENZO\pacio 2025-07-01 18:05:03 +02:00
parent e148b2fa21
commit 4387301ced
5 changed files with 149 additions and 26 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.13.3-slim
WORKDIR /app
@ -7,5 +7,6 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY watcher.py .
COPY config.yaml .
COPY templates .
CMD ["python", "-u", "watcher.py"]

View File

@ -11,7 +11,7 @@ email:
username: brass@relay.poloinformatico.it
password: DMKqP9vUYn8s
to: paciotti@poloinformatico.it
from: brass@poloinformatico.it
from: brass@relay.poloinformatico.it
webui:
enabled: true

View File

@ -4,6 +4,7 @@ services:
ports:
- "48080:8080"
volumes:
- ./config.yaml:/app/config.yml
- ./config.yaml:/app/config.yaml
- /zucchetti/infinity:/mnt/tenants:ro
- ./templates:/app/templates:ro
restart: unless-stopped

140
templates/index.html Normal file
View File

@ -0,0 +1,140 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tenant Disk Usage Dashboard</title>
<style>
:root {
--bg-color: #f5f5f5;
--text-color: #222;
--card-color: white;
}
.dark-mode {
--bg-color: #121212;
--text-color: #eee;
--card-color: #1e1e1e;
}
body {
font-family: Arial, sans-serif;
margin: 2em;
background: var(--bg-color);
color: var(--text-color);
transition: background 0.3s, color 0.3s;
}
h2 {
color: var(--text-color);
}
table {
border-collapse: collapse;
width: 100%;
background: var(--card-color);
}
th, td {
padding: 12px 15px;
border: 1px solid #888;
text-align: left;
}
th {
background-color: #0077cc;
color: white;
}
tr:nth-child(even) {
background-color: rgba(0, 0, 0, 0.05);
}
.ok {
color: limegreen;
font-weight: bold;
}
.exceeded {
color: red;
font-weight: bold;
}
.bar {
height: 16px;
}
.bar-container {
background-color: #ddd;
width: 100%;
height: 16px;
}
.top-controls {
text-align: right;
margin-bottom: 1em;
}
button {
padding: 6px 10px;
font-size: 0.9em;
cursor: pointer;
}
footer {
margin-top: 2em;
font-size: 0.9em;
color: #777;
}
</style>
</head>
<body>
<div class="top-controls">
<button onclick="toggleDarkMode()">🌙 Toggle Dark Mode</button>
</div>
<h2>📊 Tenant Folder Disk Usage</h2>
<table>
<thead>
<tr>
<th>Tenant</th>
<th>Used (GB)</th>
<th>Limit (GB)</th>
<th>Usage %</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for folder, data in results.items() %}
{% set percent = (100 * data.used_gb / data.limit_gb) | round(1) %}
<tr>
<td>{{ folder }}</td>
<td>{{ "%.2f"|format(data.used_gb) }}</td>
<td>{{ "%.2f"|format(data.limit_gb) }}</td>
<td>
<div class="bar-container">
<div class="bar" style="
width: {{ percent if percent < 100 else 100 }}%;
background-color: {{ 'red' if percent > 100 else '#0077cc' }};
"></div>
</div>
{{ percent }}%
</td>
<td class="{{ 'exceeded' if data.exceeded else 'ok' }}">
{{ 'Exceeded' if data.exceeded else 'OK' }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<footer>
Last updated: {{ now }}
</footer>
<script>
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
}
</script>
</body>
</html>

View File

@ -4,7 +4,7 @@ import yaml
import psutil
import threading
import time
from flask import Flask, render_template_string
from flask import Flask, render_template
from email.mime.text import MIMEText
import subprocess
@ -83,31 +83,12 @@ def schedule_check(interval_sec):
@app.route("/")
def index():
html = """
<html>
<head><title>Tenant Disk Usage</title></head>
<body>
<h2>Tenant Folder Disk Usage (GB)</h2>
<table border="1" cellpadding="6" cellspacing="0">
<tr><th>Tenant</th><th>Used (GB)</th><th>Limit (GB)</th><th>Status</th></tr>
{% for folder, data in results.items() %}
<tr>
<td>{{ folder }}</td>
<td>{{ "%.2f"|format(data.used_gb) }}</td>
<td>{{ "%.2f"|format(data.limit_gb) }}</td>
<td style="color: {{ 'red' if data.exceeded else 'green' }}">{{ 'Exceeded' if data.exceeded else 'OK' }}</td>
</tr>
{% endfor %}
</table>
<p>Last updated: {{ now }}</p>
</body>
</html>
"""
import datetime
return render_template_string(html, results=results, now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
return render_template("index.html", results=results, now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
if __name__ == "__main__":
interval = config.get("schedule", {}).get("seconds", 300) # default 5 minutes
interval = config.get("schedule", {}).get("seconds", 86400) # default 5 minutes
print(f"[INFO] Starting scheduled checks every {interval} seconds.")
schedule_check(interval)