-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
171 lines (156 loc) · 3.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Yakuza - DSTAT</title>
<style>
html,
body {
background: #000000 url("./style/img/bg.gif");
height: 100%;
margin: 0;
}
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
body>div {
width: 100%;
}
#chart {
width: 80%;
margin: auto;
border: 1px solid #0f0;
}
</style>
</head>
<body>
<div>
<div id="chart"></div>
</div>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script>
window.onload = () => {
let previous = null;
const charts = Highcharts.chart("chart", {
exporting: {
enabled: false,
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
event.preventDefault();
},
},
},
},
chart: {
type: "area",
style: {
fontFamily: "Arial, Helvetica, sans-serif",
},
backgroundColor: "transparent",
},
title: {
text: "L7 DSTAT",
style: {
color: "#0f0",
},
},
xAxis: {
type: "datetime",
dateTimeLabelFormats: {
day: "%a",
},
},
yAxis: {
labels: {
style: {
color: "#0f0",
},
},
title: {
text: "Requests / Sec",
margin: 50,
style: {
color: "#0f0",
},
},
},
credits: {
enabled: false,
},
legend: {
useHTML: true,
symbolWidth: 0,
labelFormatter: function () {
return `
<div>
<div style="display: inline-block; margin-right: 5px;"></div>
<span style="color: #0f0;">${this.name}</span>
</div>
`;
},
},
subtitle: {
style: {
color: "#0f0",
font: 'bold 12px "Arial, Helvetica, sans-serif',
},
},
series: [
{
type: "area",
name: "Total Requests",
color: "#0f0",
data: [],
},
],
});
async function getData() {
try {
const response = await fetch("/nginx_status", {
method: "GET",
cache: "no-cache",
});
if (response.ok) {
const text = await response.text();
let current = 0;
let lastValid = 0;
const part = text.split(' ')[9];
const series = charts.series[0];
current = parseInt(part);
if (
(current > 0 && (current - previous) > 0 && (current - previous) < 990000000) ||
(current > 0 && (current - previous) > 0 && previous === null)
) {
const shift = series.data.length > 40;
if (previous !== null) {
series.addPoint([Math.floor(Date.now()), current - previous], true, shift);
}
lastValid = current - previous;
previous = current;
} else {
previous = null;
console.log("Bad response");
}
setTimeout(getData, 1000);
} else {
throw new Error(`HTTP error! Status: ${response.status}`);
}
} catch (err) {
console.log(err);
}
}
(async () => {
await getData();
})()
};
</script>
</body>
</html>