-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstats.html
148 lines (129 loc) · 5.13 KB
/
stats.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1">
<title>tenbyten server stats</title>
<style type="text/css">
html, body {
height: 100%;
}
body {
padding: 0;
margin: 0;
overflow: hidden;
}
#container {
height: 100%;
}
</style>
<script src="vendor/standalone-framework.js"></script>
<script src="vendor/highcharts.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
var SERVER = 'http://stage.sl.pt:3000';
//var SERVER = 'http://127.0.0.1:3000';
var READING_DELTA = 5000; //ms
var NR_READINGS_IN_WINDOW = 100; // 8min 20s
var ajax = function ajax(o) {
var xhr = new XMLHttpRequest();
xhr.open(o.method || 'GET', o.uri, true);
var cbInner = function() {
if (xhr.readyState === 4 && xhr.status > 199 && xhr.status < 300) {
return o.cb(null, JSON.parse(xhr.response));
}
o.cb('error requesting ' + o.uri);
};
xhr.onload = cbInner;
xhr.onerror = cbInner;
xhr.send(o.payload || null);
};
var bytesToMB = function(n) { return n/1024/1024; };
var ch;
function fetch() {
ajax({
uri: SERVER + '/stats',
cb: function(err, o) {
if (err) { return; }
var t = (new Date()).getTime();
var s = -1;
ch.series[++s].addPoint([t, o.avgResponseTimeMs], true, true);
ch.series[++s].addPoint([t, o.status.activeSessions], true, true);
ch.series[++s].addPoint([t, o.status.highscores], true, true);
//ch.series[++s].addPoint([t, bytesToMB(o.memory.rss)], true, true);
//ch.series[++s].addPoint([t, bytesToMB(o.memory.heapUsed)], true, true);
//ch.series[++s].addPoint([t, bytesToMB(o.memory.heapTotal)], true, true);
//ch.redraw();
}
})
};
setInterval(fetch, READING_DELTA);
var getData = function() {
var data = [];
var time = (new Date()).getTime();
for (var i = -NR_READINGS_IN_WINDOW; i <= 0; i += 1) {
data.push({
x: time + i * READING_DELTA,
y: 0
});
}
return data;
};
var data0 = getData();
Highcharts.setOptions({
global: {
useUTC: false
}
});
ch = new Highcharts.Chart({
chart: {
renderTo: document.getElementById('container'),
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
ch = this;
fetch();
}
}
},
title: {
text: 'tenbyten server stats'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: [
{
labels: { format: '{value} ms' },
title: { text: 'avg response time' }
},
{
labels: { format: '{value}' },
title: { text: 'pax' }
},
{
labels: { format: '{value} MB' },
title: { text: 'memory' }
}
],
tooltip: {
shared: true,
crosshairs: true
},
series: [
{name: 'avg response time', data: data0, yAxis:0, marker: {enabled:false} },
{name: 'active sessions', data: data0, yAxis:1, marker: {enabled:false} },
{name: 'highscores', data: data0, yAxis:1, marker: {enabled:false} },
//{name: 'stack', data: data0, yAxis:2, marker: {enabled:false} },
//{name: 'heap used', data: data0, yAxis:2, marker: {enabled:false} },
//{name: 'heap total', data: data0, yAxis:2, marker: {enabled:false} },
]
});
</script>
</body>
</html>