From 52e30bfb9a4af0cd939e3746cab4546255bb2c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 15 Jun 2020 12:10:15 +0200 Subject: [PATCH] better uptime, slightly better stats formatting on small screens --- sdbs_infra/dashboard/static/main.css | 4 ++++ sdbs_infra/dashboard/views.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sdbs_infra/dashboard/static/main.css b/sdbs_infra/dashboard/static/main.css index cd4cb7d..9bb418d 100644 --- a/sdbs_infra/dashboard/static/main.css +++ b/sdbs_infra/dashboard/static/main.css @@ -102,6 +102,10 @@ main { color: darkred; } +footer { + text-align: justify; +} + footer em { font-style: normal; font-weight: bold; diff --git a/sdbs_infra/dashboard/views.py b/sdbs_infra/dashboard/views.py index 7a3509f..b951ffd 100644 --- a/sdbs_infra/dashboard/views.py +++ b/sdbs_infra/dashboard/views.py @@ -1,8 +1,9 @@ import time +from collections import namedtuple import psutil from django.views.generic import TemplateView -from humanize import naturalsize, naturaldelta +from humanize import naturalsize from sdbs_infra.dashboard.models import Service @@ -33,8 +34,18 @@ class IndexView(TemplateView): f"DISK: {naturalsize(disk.used)}/{naturalsize(disk.total)} ({disk.percent}% USED)" ) + uptime = normalize_seconds(time.time() - psutil.boot_time()) + stats.append( - f"UPTIME: {naturaldelta(time.time() - psutil.boot_time())}" + f"UPTIME: {int(uptime.days)} days, {int(uptime.hours)} hours, {int(uptime.minutes)} minutes" ) - return " / ".join(stats) + return " / ".join(map(lambda stat: stat.replace(" ", " "), 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)