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

djangoaddicts / django-hostutils / 7367497413

31 Dec 2023 01:16AM UTC coverage: 99.262%. Remained the same
7367497413

push

github

davidslusser
adding sphinx

35 of 37 branches covered (0.0%)

Branch coverage included in aggregate %.

234 of 234 relevant lines covered (100.0%)

1.0 hits per line

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

99.06
/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

10

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

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

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

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

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

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

42

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

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

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

77

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

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

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

94

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

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

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

110

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

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

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

128

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

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

135
    def get(self, request, *args, **kwargs):
1✔
136
        """allow get method"""
137
        context = {}
1✔
138
        context["title"] = self.title
1✔
139
        context["now"] = datetime.datetime.now()
1✔
140
        context["subtitle"] = psutil.os.uname()[1]
1✔
141
        counts = {"running": 0, "sleeping": 0, "idle": 0, "stopped": 0, "zombie": 0, "dead": 0, "disk-sleep": 0}
1✔
142
        process_list = []
1✔
143
        for process in psutil.process_iter():
1✔
144
            try:
1✔
145
                counts[process.status()] += 1
1✔
146
                process_list.append(
1✔
147
                    {
148
                        "pid": process.pid,
149
                        "name": process.name(),
150
                        "status": process.status(),
151
                        "started_at": process.create_time(),
152
                    }
153
                )
154
            except (psutil.NoSuchProcess, psutil.AccessDenied):
1✔
155
                pass
1✔
156
        context["counts"] = counts
1✔
157
        context["process_list"] = process_list
1✔
158
        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