forked from Loafter/WebTop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
322 lines (298 loc) · 9.24 KB
/
index.html
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!doctype html>
<html>
<head>
<title>WebTop</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootswatch/3.0.0/slate/bootstrap.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://smoothiecharts.org/smoothie.js"></script>
<style type="text/css">
/* Space out content a bit */
body {
padding-top: 20px;
padding-bottom: 20px;
}
/* Everything but the jumbotron gets side spacing for mobile first views */
.header,
.marketing,
.footer {
padding-left: 15px;
padding-right: 15px;
}
/* Custom page header */
.header {
border-bottom: 1px solid #e5e5e5;
}
/* Make the masthead heading the same height as the navigation */
.header h3 {
margin-top: 0;
margin-bottom: 0;
line-height: 40px;
padding-bottom: 19px;
}
/* Custom page footer */
.footer {
padding-top: 19px;
color: #777;
border-top: 1px solid #e5e5e5;
}
/* Customize container */
@media(min-width: 768px) {
.container {
max-width: 730px;
}
}
.container-narrow > hr {
margin: 30px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
text-align: center;
border-bottom: 1px solid #e5e5e5;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
/* Supporting marketing content */
.marketing {
margin: 40px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
/* Responsive: Portrait tablets and up */
@media screen and(min-width: 768px) {
/* Remove the padding we set earlier */
.header,
.marketing,
.footer {
padding-left: 0;
padding-right: 0;
}
/* Space out the masthead */
.header {
margin-bottom: 30px;
}
/* Remove the bottom border on the jumbotron for visual effect */
.jumbotron {
border-bottom: 0;
}
}
span.tab {
float: right
}
</style>
<script type="text/javascript">
var lastTopData = {};
var minCpuUsage = 0.000001
var cpuData = new TimeSeries();
var memData = new TimeSeries();
function createTimeline() {
var chart = new SmoothieChart({
maxValue: 100,
minValue: 0,
millisPerPixel: 100,
grid: {
fillStyle: '#3e444c'
}
});
chart.addTimeSeries(cpuData, {
lineWidth: 2,
strokeStyle: '#a0afc3',
fillStyle: 'rgba(112,127,146,0.30)'
});
chart.addTimeSeries(memData, {
lineWidth: 2,
strokeStyle: '#b0afc3',
fillStyle: 'rgba(212,127,146,0.30)'
});
chart.streamTo(document.getElementById("cpu-mem-chart"));
}
function updateChart() {
var lastCpuData = {
Total: 0,
Idle: 0
};
$.ajax({
url: "/webtop",
type: "POST",
data: '{\"Type\": \"1\"}',
dataType: "json"
}).done(function(jsonData) {
var cpuLoad = jsonData.CPUUsage.UserPct;
var MemLoad = ((jsonData.MemSample.MemUsed) / jsonData.MemSample.MemTotal) * 100;
lastCpuData = jsonData.CpuSample;
cpuData.append(new Date().getTime(), cpuLoad);
memData.append(new Date().getTime(), MemLoad);
})
}
function updateStatistic() {
var lastCpuData = {
Total: 0,
Idle: 0
};
$.ajax({
url: "/webtop",
type: "POST",
data: '{\"Type\": \"1\"}',
dataType: "json"
}).done(function(jsonData) {
//cpu table
$("#user-load-cpu").text(jsonData.CPUUsage.UserPct.toFixed(1) + ' %');
$("#system-load-cpu").text(jsonData.CPUUsage.SystemPct.toFixed(1) + ' %');
$("#idle-load-cpu").text(jsonData.CPUUsage.IdlePct.toFixed(1) + ' %');
$("#guest-load-cpu").text(jsonData.CPUUsage.GuestPct.toFixed(1) + ' %');
$("#low-load-cpu").text(jsonData.CPUUsage.IowaitPct.toFixed(1) + ' %');
//mem table
$("#buffers-mem").text((jsonData.MemSample.Buffers * 0.000976562).toFixed(1) + ' Mb')
$("#used-mem").text((jsonData.MemSample.MemUsed * 0.000976562).toFixed(1) + ' Mb')
$("#free-mem").text((jsonData.MemSample.MemFree * 0.000976562).toFixed(1) + ' Mb')
$("#total-mem").text((jsonData.MemSample.MemTotal * 0.000976562).toFixed(1) + ' Mb')
$("#cached-mem").text((jsonData.MemSample.Cached * 0.000976562).toFixed(1) + ' Mb')
})
}
function addProcessToTable(processInfo) {
pid = processInfo.Pid
Name = processInfo.Name
User = processInfo.User
Cpu = processInfo.Cpu.toFixed(1)
Mem = (processInfo.Memory * 0.000976562).toFixed(1)
inerHtml = ""
inerHtml = inerHtml.concat('<tr onclick="onClickKill(this)" id="pr-items' + pid + '"><td id="pid' + pid + '">' + pid + '</td><td id="name-id' + pid + '">' + Name + '</td><td id="user-id' + pid + '">' + User + '</td><td id="cpu-id' + pid + '">' + Cpu + '</td><td id="memory-id' + pid + '">' + Mem + '</td></tr>')
$("#process-list-table").append(inerHtml)
}
function updateProcessInTable(processInfo) {
pid = processInfo.Pid
Name = processInfo.Name
User = processInfo.User
Cpu = (processInfo.Cpu * 100).toFixed(1)
Memory = (processInfo.Memory * 0.000976562).toFixed(1)
$("#pid" + pid).text(pid)
$("#name-id" + pid).text(Name)
$("#user-id" + pid).text(User)
$("#cpu-id" + pid).text(Cpu)
$("#memory-id" + pid).text(Memory)
}
function deleteProcessFromTable(pid) {
rowId = "#pr-items" + pid
$(rowId).remove()
}
function updateTop() {
$.ajax({
url: "/webtop",
type: "POST",
data: '{\"Type\": \"2\"}',
dataType: "json"
}).done(function(jsonData) {
var topDic = {};
for (index in jsonData.ProcessItems) {
topItems = jsonData.ProcessItems[index]
if (minCpuUsage <= topItems.Cpu) {
topDic[topItems.Pid] = topItems;
}
}
console.log("_______________________________________________________________________________________________________________________________________________________________________________________________")
if (Object.keys(lastTopData).length == 0) {
lastTopData = topDic
console.log("full new table")
for (index in topDic) {
addProcessToTable(topDic[index])
}
} else {
itemsforRemove = lastTopData
for (index in topDic) {
pid = topDic[index].Pid
if (!(lastTopData[pid] === undefined)) {
console.log("updated " + JSON.stringify(topDic[index].Pid))
updateProcessInTable(topDic[index])
} else {
console.log("added " + JSON.stringify(topDic[index].Pid))
addProcessToTable(topDic[index])
}
}
for (index in itemsforRemove) {
if ((topDic[index] === undefined)) {
console.log("deleted " + JSON.stringify(itemsforRemove[index].Pid))
deleteProcessFromTable(itemsforRemove[index].Pid)
}
}
}
lastTopData = topDic
})
}
function onDocumentLoad() {
createTimeline()
setInterval(updateChart, 500);
setInterval(updateStatistic, 700);
setInterval(updateTop, 700)
}
function onClickKill(e) {
pid = e.id.substring(8)
$.ajax({
url: "/webtop",
type: "POST",
data: '{\"Type\": \"3\",\"Pid": ' + pid + '}',
dataType: "json"
})
}
function switchUsage() {
if (minCpuUsage == 0.0) {
minCpuUsage = 0.000001
$("#cpu-minum").text(">0")
} else if (minCpuUsage == 0.000001) {
minCpuUsage = 0.25
$("#cpu-minum").text(">25")
} else if (minCpuUsage == 0.25) {
minCpuUsage = 0.5
$("#cpu-minum").text(">50")
} else if (minCpuUsage == 0.5) {
minCpuUsage = 0.75
$("#cpu-minum").text(">75")
} else if (minCpuUsage == 0.75) {
minCpuUsage = 0
$("#cpu-minum").text(">=0")
}
}
</script>
</head>
<body onload="onDocumentLoad()">
<div class="container">
<h1>WebTop system monitor</h1>
<div class="panel-footer">System state </div>
<div class="panel-body" data-ds-editmark="true">
<div class="row">
<div class="col-md-4"> <span class="label label-default">Cpu load</span>
<p>User:<span class="tab" id="user-load-cpu">10%</span> </p>
<p>System:<span class="tab" id="system-load-cpu">10%</span> </p>
<p>Idle:<span class="tab" id="idle-load-cpu">10%</span> </p>
<p>Guest:<span class="tab" id="guest-load-cpu">10%</span> </p>
<p>Low:<span class="tab" id="low-load-cpu">10%</span> </p>
</div>
<div class="col-md-4"> <span class="label label-default">System info</span>
<p>Memory used:<span class="tab" id="used-mem">10%</span> </p>
<p>Memory free:<span class="tab" id="free-mem">10%</span> </p>
<p>Buffers:<span class="tab" id="buffers-mem">10%</span> </p>
<p>Cached:<span class="tab" id="cached-mem">10%</span> </p>
<p>Memory total:<span class="tab" id="total-mem">10%</span> </p>
</div>
<div class="col-md-4"> <span class="label label-default">Cpu graph</span> <span class="tab"> <canvas id="cpu-mem-chart" width="218" height="138"></canvas></span> </div>
</div>
</div>
<div class="panel-footer">Process list </div>
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Pid</th>
<th>Process name</th>
<th>User id</th>
<th>Cpu <span onclick="switchUsage()" id="cpu-minum">>=0</span>%</th>
<th>Mem Mb.</th>
</tr>
</thead>
<tbody id="process-list-table"> </tbody>
</table>
<div class="panel-body" data-ds-editmark="true"></div>
</div>
</body>