better uptime, slightly better stats formatting on small screens

This commit is contained in:
Tomáš Mládek 2020-06-15 12:10:15 +02:00
parent c4c38324e9
commit 52e30bfb9a
2 changed files with 18 additions and 3 deletions

View file

@ -102,6 +102,10 @@ main {
color: darkred; color: darkred;
} }
footer {
text-align: justify;
}
footer em { footer em {
font-style: normal; font-style: normal;
font-weight: bold; font-weight: bold;

View file

@ -1,8 +1,9 @@
import time import time
from collections import namedtuple
import psutil import psutil
from django.views.generic import TemplateView from django.views.generic import TemplateView
from humanize import naturalsize, naturaldelta from humanize import naturalsize
from sdbs_infra.dashboard.models import Service from sdbs_infra.dashboard.models import Service
@ -33,8 +34,18 @@ class IndexView(TemplateView):
f"<em>DISK:</em> {naturalsize(disk.used)}/{naturalsize(disk.total)} ({disk.percent}% USED)" f"<em>DISK:</em> {naturalsize(disk.used)}/{naturalsize(disk.total)} ({disk.percent}% USED)"
) )
uptime = normalize_seconds(time.time() - psutil.boot_time())
stats.append( stats.append(
f"<em>UPTIME:</em> {naturaldelta(time.time() - psutil.boot_time())}" f"<em>UPTIME:</em> {int(uptime.days)} days, {int(uptime.hours)} hours, {int(uptime.minutes)} minutes"
) )
return " / ".join(stats) return " / ".join(map(lambda stat: stat.replace(" ", "&nbsp;"), stats))
def normalize_seconds(seconds: int):
(days, remainder) = divmod(seconds, 86400)
(hours, remainder) = divmod(remainder, 3600)
(minutes, seconds) = divmod(remainder, 60)
return namedtuple("_", ("days", "hours", "minutes", "seconds"))(days, hours, minutes, seconds)