-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.html
executable file
·220 lines (218 loc) · 8.29 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
<!--
Autor: Mario Pérez Esteso <[email protected]>
Web: geekytheory.com
-->
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Raspberry Pi Status
</title>
<!-- Importo el módulo socket.io que tengo en el proyecto -->
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Importo el archivo Javascript de Highcharts directamente desde su servidor -->
<!--<script src="http://code.highcharts.com/highcharts.js" type="application/javascript"></script>-->
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="container">
<div class="row marketing">
<div class="col-lg-4">
<div class="panel panel-primary">
<div class="panel-heading">General info</div>
<div class="panel-body">
<p id="p_hostname">Here you can see the general info of the Raspberry Pi</p>
<p id="p_kernel"></p>
<p id="p_uptime"></p>
<div>
<b>Top list:</b>
<ol id="toplist">
</ol>
</div>
</div>
</div>
</div>
<div class="col-lg-8">
<div id="chartMemory" style="min-width: 100; height:250px; margin: 0 auto"></div>
</div>
</div>
<div class="row marketing">
<div class="col-lg-6">
<div class="container" id="chart" style="width:100%; height:300px;"></div>
</div>
<div class="col-lg-6">
<div class="container" id="cpu_usage" style="width:100%; height:300px;"></div>
</div>
</div>
<!-- Creo el div donde tendré la gráfica. Le digo que ocupe todo el ancho
de la pantalla y 400px de alto -->
<!-- Comienza el Javascript -->
<script>
// Creo un WebSocket. ¡Poned la IP de vuestra Raspberry Pi!
var socket = io.connect('http://'+ location.host);
// console.log(location.host)
// Creo un nuevo objeto 'Chart'
var chart, chartCPU, chartMem, memTotal;
chart = new Highcharts.StockChart({
chart: {
renderTo: 'chart',
defaultSeriesType: 'spline',
events: {
load: function() {
// Cada vez que reciba un valor desde el socket, lo meto en la gráfica
socket.on('temperatureUpdate', function (time, data) {
var series = chart.series[0];
series.addPoint([time, data]);
});
}
}
},
rangeSelector : {
selected : 100
},
title: {
text: 'CPU Temperature Raspberry Pi'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Temperature ºC',
margin: 10
}
},
series: [{
name: 'Temperature',
data: []
}],
credits: {
enabled: false
}
});
chartCPU = new Highcharts.StockChart({
chart: {
renderTo: 'cpu_usage',
defaultSeriesType: 'spline',
events: {
load: function() {
// Cada vez que reciba un valor desde el socket, lo meto en la gráfica
socket.on('cpuUsageUpdate', function (time, data) {
var series = chartCPU.series[0];
series.addPoint([time, data]);
});
}
}
},
rangeSelector : {
selected : 100
},
title: {
text: 'CPU Load Raspberry Pi'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'CPU Load (%)',
margin: 10
}
},
series: [{
name: 'CPU Load',
data: []
}],
credits: {
enabled: false
}
});
chartMem = new Highcharts.Chart({
chart: {
renderTo: 'chartMemory',
type: 'bar',
events: {
load: function() {
// Cada vez que reciba un valor desde el socket, lo meto en la gráfica
socket.on('memoryUpdate', function (free, used, buffered, cached) {
chartMem.series[0].setData([{y: used, color: 'red'}, {y: free, color: 'green'}, {y: buffered, color: 'blue'}, {y: cached, color: 'orange'}]);
});
}
}
},
title: {
text: 'Memory'
},
xAxis: {
categories: ['Used', 'Free', 'Buffered', 'Cached'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: "Percentage",
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' %'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
credits: {
enabled: false
},
series: [{
name: "Memory",
data: [{y: 0, color: 'red'}, {y: 0, color: 'green'}, {y: 0, color: 'blue'}, {y: 0, color: 'orange'}]
}]
});
socket.on('hostname', function (hname) {
document.getElementById("p_hostname").innerHTML="<b>Hostname:</b> "+hname;
});
socket.on('kernel', function (ker) {
document.getElementById("p_kernel").innerHTML="<b>Kernel:</b> "+ker;
});
socket.on('uptime', function (uptime) {
document.getElementById("p_uptime").innerHTML="<b>Up time:</b> "+ uptime;
});
socket.on('toplist', function (toplist) {
const res = toplist.split("\n");
const result = res.filter(item => item).map(item => `<li>${item}</li>`).join("");
document.getElementById("toplist").innerHTML=result;
});
socket.on('memoryTotal', function (mem) {
chartMem.setTitle({text:"Memory: "+mem+" KB"});
memTotal = mem;
});
</script>
</body>
</html>