-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.jinja
executable file
·139 lines (118 loc) · 3.72 KB
/
server.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if config['chartjs'] %}
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.2"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.30.1"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@1.0.1"></script>
{% endif %}
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<title>systemdrip</title>
<style>
body {
font-family: Arial, sans-serif;
}
table {
border-collapse: collapse;
}
th,
td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
.container {
display: flex;
flex-wrap: wrap;
}
canvas {
width: 44vw;
max-height: 500px;
}
.container canvas {
margin: 5px;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
width: 90vw;
}
}
</style>
</head>
<body>
<h2>SystemDrip</h2>
{% if systemdrip_table %}
<p>Last Updated: {{ d_meta["last_updated"] }} ({{ last_update_mins }} mins ago)</p>
{{ systemdrip_table }}
{% else %}
<p>Metrics uninitialized. Has <code>python3 systemdrip.py</code> ran yet?</p>
{% endif %}
<div class="container">
{% if memory_data %}
<div class="item">
<h2>Memory Usage</h2>
<canvas id="memoryChart"></canvas>
</div>
{% endif %}
{% if cpu_data %}
<div class="item">
<h2>CPU Usage</h2>
<canvas id="cpuChart"></canvas>
</div>
{% endif %}
</div>
<p>View source code on <a href="https://github.com/skwzrd/systemdrip">GitHub</a></p>
<script>
setInterval(function () {
location.reload();
}, 1000 * 60 * 1); // page will reload every 1 minute(s)
{% if memory_data %}
plot_2d('memoryChart', {{ memory_data | tojson }}, 'm');
{% endif %}
{% if cpu_data %}
plot_2d('cpuChart', {{ cpu_data | tojson }}, 'c');
{% endif %}
function plot_2d(id, server_data, col) {
if (server_data) {
var chartCtx = document.getElementById(id).getContext('2d');
var chart = new Chart(chartCtx, {
type: 'line',
data: {
datasets: server_data.map(obj => ({
label: obj.l,
data: obj.d.map(entry => ({ x: entry.t, y: entry[col] }))
}))
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'day',
unitStepSize: 1,
displayFormats: {
'day': 'MMM DD'
}
},
},
y: {
type: 'logarithmic',
}
},
animation: {
duration: 0
},
maintainAspectRatio: false,
},
});
}
}
</script>
</body>
</html>