2020-06-14 18:45:58 +02:00
|
|
|
import psutil
|
2020-06-14 12:08:11 +02:00
|
|
|
from django.views.generic import TemplateView
|
2020-06-14 19:51:35 +02:00
|
|
|
from humanize import naturalsize
|
2020-06-14 12:08:11 +02:00
|
|
|
|
|
|
|
from sdbs_infra.dashboard.models import Service
|
|
|
|
|
|
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
|
|
template_name = "index.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
return {
|
2020-06-14 18:45:58 +02:00
|
|
|
'services': Service.objects.all(),
|
2020-06-14 19:51:35 +02:00
|
|
|
'vps_stats': self.vps_stats()
|
2020-06-14 12:08:11 +02:00
|
|
|
}
|
2020-06-14 19:51:35 +02:00
|
|
|
|
|
|
|
# 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)
|