add humanize; stats formatting

This commit is contained in:
Tomáš Mládek 2020-06-14 19:51:35 +02:00
parent ffb07c2b7e
commit ab510fac1e
5 changed files with 44 additions and 7 deletions

17
poetry.lock generated
View file

@ -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"},

View file

@ -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]

View file

@ -100,4 +100,9 @@ main {
.status-down .service-status {
color: darkred;
}
footer em {
font-style: normal;
font-weight: bold;
}

View file

@ -33,7 +33,7 @@
{% endfor %}
</main>
<footer>
VPS STATS &mdash; {{ vps_stats }}
VPS STATS &mdash; {{ vps_stats|safe }}
</footer>
</body>
</html>

View file

@ -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"<em>LOAD AVG:</em> {', '.join(map(str, psutil.getloadavg()))}")
memory = psutil.virtual_memory()
stats.append(
f"<em>MEM:</em> {naturalsize(memory.used)}/{naturalsize(memory.total)} ({memory.percent}% USED)"
)
disk = psutil.disk_usage('/')
stats.append(
f"<em>DISK:</em> {naturalsize(disk.used)}/{naturalsize(disk.total)} ({disk.percent}% USED)"
)
return " / ".join(stats)