diff --git a/poetry.lock b/poetry.lock index 7d9e194..8a32ba1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -49,6 +49,17 @@ optional = false python-versions = "*" version = "3.4.1" +[[package]] +category = "main" +description = "Python humanize utilities" +name = "humanize" +optional = false +python-versions = ">=3.5" +version = "2.4.0" + +[package.extras] +tests = ["freezegun", "pytest", "pytest-cov"] + [[package]] category = "main" description = "Python Imaging Library (Fork)" @@ -93,7 +104,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "0.3.1" [metadata] -content-hash = "f75bdf08cdd88dbaee13ad801096db3236efb2858c38232f9be05973f3e72cd7" +content-hash = "c2be494386f51759b009fd7ed3aead33cb56578ddf36c2102d7c3bb10e7bf056" python-versions = "^3.7" [metadata.files] @@ -114,6 +125,10 @@ django-ordered-model = [ {file = "django-ordered-model-3.4.1.tar.gz", hash = "sha256:d867166ed4dd12501139e119cbbc5b4d19798a3e72740aef0af4879ba97102cf"}, {file = "django_ordered_model-3.4.1-py3-none-any.whl", hash = "sha256:29af6624cf3505daaf0df00e2df1d0726dd777b95e08f304d5ad0264092aa934"}, ] +humanize = [ + {file = "humanize-2.4.0-py3-none-any.whl", hash = "sha256:07dd1293bac6c77daa5ccdc22c0b41b2315bee0e339a9f035ba86a9f1a272002"}, + {file = "humanize-2.4.0.tar.gz", hash = "sha256:42ae7d54b398c01bd100847f6cb0fc9e381c21be8ad3f8e2929135e48dbff026"}, +] pillow = [ {file = "Pillow-7.1.2-cp35-cp35m-macosx_10_10_intel.whl", hash = "sha256:ae2b270f9a0b8822b98655cb3a59cdb1bd54a34807c6c56b76dd2e786c3b7db3"}, {file = "Pillow-7.1.2-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:d23e2aa9b969cf9c26edfb4b56307792b8b374202810bd949effd1c6e11ebd6d"}, diff --git a/pyproject.toml b/pyproject.toml index 30d0c23..a0161a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ django-ordered-model = "^3.4.1" Pillow = "^7.1.2" beautifulsoup4 = "^4.9.1" psutil = "^5.7.0" +humanize = "^2.4.0" [tool.poetry.dev-dependencies] diff --git a/sdbs_infra/dashboard/static/main.css b/sdbs_infra/dashboard/static/main.css index 7a45996..cd4cb7d 100644 --- a/sdbs_infra/dashboard/static/main.css +++ b/sdbs_infra/dashboard/static/main.css @@ -100,4 +100,9 @@ main { .status-down .service-status { color: darkred; +} + +footer em { + font-style: normal; + font-weight: bold; } \ No newline at end of file diff --git a/sdbs_infra/dashboard/templates/index.html b/sdbs_infra/dashboard/templates/index.html index f314a79..13861ff 100644 --- a/sdbs_infra/dashboard/templates/index.html +++ b/sdbs_infra/dashboard/templates/index.html @@ -33,7 +33,7 @@ {% endfor %} \ No newline at end of file diff --git a/sdbs_infra/dashboard/views.py b/sdbs_infra/dashboard/views.py index ad3f0c6..bef4a19 100644 --- a/sdbs_infra/dashboard/views.py +++ b/sdbs_infra/dashboard/views.py @@ -1,5 +1,6 @@ import psutil from django.views.generic import TemplateView +from humanize import naturalsize from sdbs_infra.dashboard.models import Service @@ -8,11 +9,26 @@ class IndexView(TemplateView): template_name = "index.html" def get_context_data(self, **kwargs): - vps_stats = f"LOAD AVG: {', '.join(map(str, psutil.getloadavg()))} / " \ - f"MEM: {psutil.virtual_memory().percent}% USED / " \ - f"DISK: {psutil.disk_usage('/').percent}% USED" - return { 'services': Service.objects.all(), - 'vps_stats': vps_stats + 'vps_stats': self.vps_stats() } + + # noinspection PyListCreation + @staticmethod + def vps_stats(): + stats = [] + + stats.append(f"LOAD AVG: {', '.join(map(str, psutil.getloadavg()))}") + + memory = psutil.virtual_memory() + stats.append( + f"MEM: {naturalsize(memory.used)}/{naturalsize(memory.total)} ({memory.percent}% USED)" + ) + + disk = psutil.disk_usage('/') + stats.append( + f"DISK: {naturalsize(disk.used)}/{naturalsize(disk.total)} ({disk.percent}% USED)" + ) + + return " / ".join(stats)