• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

djangoaddicts / django-hostutils / 5305512247

pending completion
5305512247

push

github-actions

davidslusser
adding isort; adding additional badges to readme

60 of 60 branches covered (100.0%)

Branch coverage included in aggregate %.

247 of 247 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/djangoaddicts/hostutils/views/gui.py
1
import datetime
1✔
2

3
import psutil
1✔
4
from dateutil.relativedelta import relativedelta
1✔
5
from django.shortcuts import render
1✔
6
from django.views.generic import View
1✔
7

8
# import forms
9
from djangoaddicts.hostutils.forms import HostProcessFilterForm
1✔
10

11

12
class ShowHost(View):
1✔
13
    """Display dashboard like page showing an overview of host data"""
14

15
    template_name = "hostutils/bs5/detail/detail_host.html"
1✔
16
    title = "Host Dashboard"
1✔
17

18
    def get(self, request, *args, **kwargs):
1✔
19
        """allow get method"""
20
        now = datetime.datetime.now()
1✔
21
        context = {}
1✔
22
        context["title"] = self.title
1✔
23
        context["subtitle"] = psutil.os.uname()[1]
1✔
24
        context["cpu_count"] = psutil.cpu_count(logical=False)
1✔
25
        context["memory"] = psutil.virtual_memory()
1✔
26
        context["disk_usage"] = psutil.disk_usage("/")
1✔
27
        context["disk_io_counters"] = psutil.disk_io_counters()
1✔
28
        context["network"] = psutil.net_connections()
1✔
29
        context["pids"] = psutil.pids()
1✔
30

31
        boot_time = psutil.boot_time()
1✔
32
        diff = relativedelta(now, datetime.datetime.fromtimestamp(boot_time))
1✔
33
        context["times"] = {}
1✔
34
        context["times"]["boot_time"] = datetime.datetime.fromtimestamp(boot_time)
1✔
35
        context["times"]["up_time"] = (
1✔
36
            f"{diff.days} days, {diff.hours} hours, {diff.minutes} minutes, " f"{diff.seconds} seconds"
37
        )
38

39
        context["platform"] = psutil.os.uname()
1✔
40

41
        return render(request, self.template_name, context=context)
1✔
42

43

44
class ShowHostCpu(View):
1✔
45
    """Display dashboard like page showing host cpu data"""
46

47
    template_name = "hostutils/bs5/detail/cpu.html"
1✔
48
    title = "CPU Dashboard"
1✔
49

50
    def get(self, request, *args, **kwargs):
1✔
51
        """CPU Dashboard"""
52
        context = {}
1✔
53
        context["title"] = self.title
1✔
54
        context["subtitle"] = psutil.os.uname()[1]
1✔
55
        context["stats"] = psutil.cpu_stats()
1✔
56
        context["physical_count"] = psutil.cpu_count(logical=False)
1✔
57
        context["logical_count"] = psutil.cpu_count(logical=True)
1✔
58
        context["percent"] = psutil.cpu_percent(interval=None)
1✔
59
        context["times_list"] = psutil.cpu_times(percpu=True)
1✔
60
        context["times_percent_list"] = psutil.cpu_times_percent(percpu=True)
1✔
61
        context["percent_list"] = psutil.cpu_percent(interval=None, percpu=True)
1✔
62
        context["frequency_list"] = psutil.cpu_freq(percpu=True)
1✔
63
        context["cpu_range"] = list(range(psutil.cpu_count(logical=True)))
1✔
64
        cpu_data = {}
1✔
65
        for i in range(context["logical_count"]):
1✔
66
            cpu_data[i] = {
1✔
67
                "times": context["times_list"][i],
68
                "time_percent": context["times_percent_list"][i],
69
                "percent": context["percent_list"][i],
70
                "frequency": context["frequency_list"][i],
71
            }
72
        context["cpu_data"] = cpu_data
1✔
73
        context["load_avg_1"], context["load_avg_5"], context["load_avg_15"] = [
1✔
74
            round(x / psutil.cpu_count() * 100, 2) for x in psutil.getloadavg()
75
        ]
76
        return render(request, self.template_name, context=context)
1✔
77

78

79
class ShowHostDisk(View):
1✔
80
    """Display dashboard like page showing host disk data"""
81

82
    template_name = "hostutils/bs5/detail/disk.html"
1✔
83
    title = "Disk Dashboard"
1✔
84

85
    def get(self, request, *args, **kwargs):
1✔
86
        """allow get method"""
87
        context = {}
1✔
88
        context["title"] = self.title
1✔
89
        context["subtitle"] = psutil.os.uname()[1]
1✔
90
        context["usage"] = psutil.disk_usage("/")
1✔
91
        context["io_counters"] = psutil.disk_io_counters()
1✔
92
        context["partition_lists"] = psutil.disk_partitions()
1✔
93
        return render(request, self.template_name, context=context)
1✔
94

95

96
class ShowHostMemory(View):
1✔
97
    """Display dashboard like page showing host memory data"""
98

99
    template_name = "hostutils/bs5/detail/memory.html"
1✔
100
    title = "Memory Dashboard"
1✔
101

102
    def get(self, request, *args, **kwargs):
1✔
103
        """allow get method"""
104
        context = {}
1✔
105
        context["title"] = self.title
1✔
106
        context["subtitle"] = psutil.os.uname()[1]
1✔
107
        context["virtual"] = psutil.virtual_memory()
1✔
108
        context["swap"] = psutil.swap_memory()
1✔
109
        return render(request, self.template_name, context=context)
1✔
110

111

112
class ShowHostNetwork(View):
1✔
113
    """Display dashboard like page showing host network data"""
114

115
    template_name = "hostutils/bs5/detail/network.html"
1✔
116
    title = "Network Dashboard"
1✔
117

118
    def get(self, request, *args, **kwargs):
1✔
119
        """allow get method"""
120
        context = {}
1✔
121
        context["title"] = self.title
1✔
122
        context["subtitle"] = psutil.os.uname()[1]
1✔
123
        context["connection_list"] = psutil.net_connections()
1✔
124
        context["interface_list"] = psutil.net_if_addrs()
1✔
125
        context["stats_list"] = psutil.net_if_stats()
1✔
126
        context["counters"] = psutil.net_io_counters()
1✔
127
        return render(request, self.template_name, context=context)
1✔
128

129

130
class ShowHostProcesses(View):
1✔
131
    """Display dashboard like page showing host process data"""
132

133
    template_name = "hostutils/bs5/detail/processes.html"
1✔
134
    title = "Process Dashboard"
1✔
135

136
    def get(self, request, *args, **kwargs):
1✔
137
        """allow get method"""
138
        context = {}
1✔
139
        context["title"] = self.title
1✔
140
        context["now"] = datetime.datetime.now()
1✔
141
        context["subtitle"] = psutil.os.uname()[1]
1✔
142
        process_list = list(psutil.process_iter())
1✔
143
        context["process_list"] = process_list
1✔
144
        counts = {
1✔
145
            "running": len([i for i in process_list if i.status() == "running"]),
146
            "sleeping": len([i for i in process_list if i.status() == "sleeping"]),
147
            "idle": len([i for i in process_list if i.status() == "idle"]),
148
            "stopped": len([i for i in process_list if i.status() == "stopped"]),
149
            "zombie": len([i for i in process_list if i.status() == "zombie"]),
150
            "dead": len([i for i in process_list if i.status() == "dead"]),
151
        }
152
        context["counts"] = counts
1✔
153
        filter_form = {}
1✔
154
        filter_form["form"] = HostProcessFilterForm(request.GET or None)
1✔
155
        filter_form["modal_name"] = "filter_processes"
1✔
156
        filter_form["modal_size"] = "modal-lg"
1✔
157
        filter_form["modal_title"] = "Filter Host Processes"
1✔
158
        filter_form["hx_method"] = "hx-get"
1✔
159
        filter_form["hx_url"] = "/hostutils/get_host_processes"
1✔
160
        filter_form["hx_target"] = "id_process_list_container"
1✔
161
        filter_form["method"] = "GET"
1✔
162
        filter_form["action"] = "Filter"
1✔
163
        context["filter_form"] = filter_form
1✔
164
        return render(request, self.template_name, context=context)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc