-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
apistats.html
369 lines (330 loc) · 13.3 KB
/
apistats.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<ul class="nav nav-tabs" style="position: relative; top: 1px">
<li class="nav-item">
<span class="title text-default">API stats</span>
</li>
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#helix">HELIX</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#kraken">KRAKEN</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tmi">TMI</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#unofficial">UNOFFICIAL</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="helix">
<div class="widget">
<canvas id="helixChart" width="400" height="100"></canvas>
<table class="table table-responsive">
<thead class="thead-dark">
<tr>
<th scope="col">time</th>
<th scope="col">call</th>
<th scope="col">endpoint</th>
<th scope="col">status</th>
<th scope="col">remaining API calls</th>
</tr>
</thead>
<tbody class="helixData"></tbody>
</table>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="kraken">
<div class="widget">
<canvas id="krakenChart" width="400" height="100"></canvas>
<table class="table table-responsive">
<thead class="thead-dark">
<tr>
<th scope="col">time</th>
<th scope="col">call</th>
<th scope="col">endpoint</th>
<th scope="col">status</th>
</tr>
</thead>
<tbody class="krakenData"></tbody>
</table>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="tmi">
<div class="widget">
<canvas id="tmiChart" width="400" height="100"></canvas>
<table class="table table-responsive">
<thead class="thead-dark">
<tr>
<th scope="col">time</th>
<th scope="col">call</th>
<th scope="col">endpoint</th>
<th scope="col">status</th>
</tr>
</thead>
<tbody class="tmiData"></tbody>
</table>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="unofficial">
<div class="widget">
<canvas id="unofficialChart" width="400" height="100"></canvas>
<table class="table table-responsive">
<thead class="thead-dark">
<tr>
<th scope="col">time</th>
<th scope="col">call</th>
<th scope="col">endpoint</th>
<th scope="col">status</th>
</tr>
</thead>
<tbody class="unofficialData"></tbody>
</table>
</div>
</div>
</div>
<script>
var lastTimestampFetched = 0
socket.emit('getApiStats')
setInterval(() => socket.emit('getApiStats', { from: lastTimestampFetched }), 60000)
var helixChart = new Chart(document.getElementById("helixChart").getContext('2d'), { type: 'line', options: { scales: { yAxes: [{ ticks: { beginAtZero:true, stepSize: 1 } }] } } })
var krakenChart = new Chart(document.getElementById("krakenChart").getContext('2d'), { type: 'line', options: { scales: { yAxes: [{ ticks: { beginAtZero:true, stepSize: 1 } }] } } })
var tmiChart = new Chart(document.getElementById("tmiChart").getContext('2d'), { type: 'line', options: { scales: { yAxes: [{ ticks: { beginAtZero:true, stepSize: 1 } }] } } })
var unofficialChart = new Chart(document.getElementById("unofficialChart").getContext('2d'), { type: 'line', options: { scales: { yAxes: [{ ticks: { beginAtZero:true, stepSize: 1 } }] } } })
$('.helixData').empty()
$('.krakenData').empty()
$('.tmiData').empty()
$('.unofficialChart').empty()
helixChart.clear()
krakenChart.clear()
tmiChart.clear()
unofficialChart.clear()
socket.off('api.stats')
socket.on('api.stats', (data) => {
data = _.orderBy(data, 'timestamp', 'asc')
lastTimestampFetched = _.get(data[data.length - 1], 'timestamp', 0)
for (c of data) {
let tBody = `.${c.api}Data`
c.code = _.get(c, 'code', 200) // set default to 200
$(tBody).prepend(
`
<tr class="${c.code.toString().startsWith('2') ? '' : 'font-weight-bold text-danger'}">
<th scope="row">${moment(c.timestamp).format('LTS')}</th>
<td>${c.call}</td>
<td><div style="word-wrap: break-word; font-family: Monospace">${c.endpoint}</div></td>
<td>${c.code}</td>
${c.remaining ? `<td>${c.remaining}</td>` : ''}
</tr>
`
)
}
const helixData = _.filter(data, (o) => o.api === 'helix')
const krakenData = _.filter(data, (o) => o.api === 'kraken')
const tmiData = _.filter(data, (o) => o.api === 'tmi')
const unofficialData = _.filter(data, (o) => o.api === 'unofficial')
let helixTimestampsPerMinute = {}
let helixTimestampsErrorsPerMinute = {}
let krakenTimestampsPerMinute = {}
let krakenTimestampsErrorsPerMinute = {}
let tmiTimestampsPerMinute = {}
let tmiTimestampsErrorsPerMinute = {}
let unofficialTimestampsPerMinute = {}
let unofficialTimestampsErrorsPerMinute = {}
let lastTimestampSaved = 0
for (let timestamp of _.map(helixData, 'timestamp')) {
// timestamps needs to be reversed as we have data from newest to oldest
if (timestamp >= lastTimestampSaved + 60000) {
lastTimestampSaved = timestamp
helixTimestampsPerMinute[lastTimestampSaved] = []
helixTimestampsErrorsPerMinute[lastTimestampSaved] = []
}
if (_.find(helixData, (o) => o.code !== 200 && o.timestamp === timestamp)) {
helixTimestampsErrorsPerMinute[lastTimestampSaved].push(timestamp)
}
helixTimestampsPerMinute[lastTimestampSaved].push(timestamp)
}
for (let index in helixTimestampsPerMinute) {
helixTimestampsPerMinute[index] = helixTimestampsPerMinute[index].length
}
for (let index in helixTimestampsErrorsPerMinute) {
helixTimestampsErrorsPerMinute[index] = helixTimestampsErrorsPerMinute[index].length
}
lastTimestampSaved = 0
for (let timestamp of _.map(krakenData, 'timestamp')) {
// timestamps needs to be reversed as we have data from newest to oldest
if (timestamp >= lastTimestampSaved + 60000) {
lastTimestampSaved = timestamp
krakenTimestampsPerMinute[lastTimestampSaved] = []
krakenTimestampsErrorsPerMinute[lastTimestampSaved] = []
}
if (_.find(krakenData, (o) => o.code !== 200 && o.timestamp === timestamp)) {
krakenTimestampsErrorsPerMinute[lastTimestampSaved].push(timestamp)
}
krakenTimestampsPerMinute[lastTimestampSaved].push(timestamp)
}
for (let index in krakenTimestampsPerMinute) {
krakenTimestampsPerMinute[index] = krakenTimestampsPerMinute[index].length
}
for (let index in krakenTimestampsErrorsPerMinute) {
krakenTimestampsErrorsPerMinute[index] = krakenTimestampsErrorsPerMinute[index].length
}
lastTimestampSaved = 0
for (let timestamp of _.map(tmiData, 'timestamp')) {
// timestamps needs to be reversed as we have data from newest to oldest
if (timestamp >= lastTimestampSaved + 60000) {
lastTimestampSaved = timestamp
tmiTimestampsPerMinute[lastTimestampSaved] = []
tmiTimestampsErrorsPerMinute[lastTimestampSaved] = []
}
if (_.find(tmiData, (o) => o.code !== 200 && o.timestamp === timestamp)) {
tmiTimestampsErrorsPerMinute[lastTimestampSaved].push(timestamp)
}
tmiTimestampsPerMinute[lastTimestampSaved].push(timestamp)
}
for (let index in tmiTimestampsPerMinute) {
tmiTimestampsPerMinute[index] = tmiTimestampsPerMinute[index].length
}
for (let index in tmiTimestampsErrorsPerMinute) {
tmiTimestampsErrorsPerMinute[index] = tmiTimestampsErrorsPerMinute[index].length
}
lastTimestampSaved = 0
for (let timestamp of _.map(unofficialData, 'timestamp')) {
// timestamps needs to be reversed as we have data from newest to oldest
if (timestamp >= lastTimestampSaved + 60000) {
lastTimestampSaved = timestamp
unofficialTimestampsPerMinute[lastTimestampSaved] = []
unofficialTimestampsErrorsPerMinute[lastTimestampSaved] = []
}
if (_.find(unofficialData, (o) => o.code !== 200 && o.timestamp === timestamp)) {
unofficialTimestampsErrorsPerMinute[lastTimestampSaved].push(timestamp)
}
unofficialTimestampsPerMinute[lastTimestampSaved].push(timestamp)
}
for (let index in unofficialTimestampsPerMinute) {
unofficialTimestampsPerMinute[index] = unofficialTimestampsPerMinute[index].length
}
for (let index in unofficialTimestampsErrorsPerMinute) {
unofficialTimestampsErrorsPerMinute[index] = unofficialTimestampsErrorsPerMinute[index].length
}
/* HELIX CHART DATA*/
for (let label of _.map(_.keys(helixTimestampsPerMinute), (o) => moment(parseInt(o, 10)).format('LTS'))) {
helixChart.data.labels.push(label)
}
for (let count of _.values(helixTimestampsPerMinute)) {
if (_.isNil(helixChart.data.datasets[0])) {
helixChart.data.datasets.push({
label: 'HELIX API calls',
data: [ count ],
backgroundColor: 'rgba(0, 0, 255, 0.2)',
borderColor: 'rgba(0, 0, 255, 0.5)'
})
} else helixChart.data.datasets[0].data.push(count)
}
for (let count of _.values(helixTimestampsErrorsPerMinute)) {
if (_.isNil(helixChart.data.datasets[1])) {
helixChart.data.datasets.push({
label: 'ERRORS',
data: [ count ],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 0.5)',
})
} else helixChart.data.datasets[1].data.push(count)
}
helixChart.update()
for (let count of _.values(helixTimestampsPerMinute)) {
if (_.isNil(helixChart.data.datasets[0])) {
helixChart.data.datasets.push({
label: 'HELIX API calls',
data: [ count ],
backgroundColor: 'rgba(0, 0, 255, 0.2)',
borderColor: 'rgba(0, 0, 255, 0.5)'
})
} else helixChart.data.datasets[0].data.push(count)
}
for (let count of _.values(helixTimestampsErrorsPerMinute)) {
if (_.isNil(helixChart.data.datasets[1])) {
helixChart.data.datasets.push({
label: 'ERRORS',
data: [ count ],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 0.5)',
})
} else helixChart.data.datasets[1].data.push(count)
}
helixChart.update()
/* KRAKEN CHART DATA */
for (let label of _.map(_.keys(krakenTimestampsPerMinute), (o) => moment(parseInt(o, 10)).format('LTS'))) {
krakenChart.data.labels.push(label)
}
for (let count of _.values(krakenTimestampsPerMinute)) {
if (_.isNil(krakenChart.data.datasets[0])) {
krakenChart.data.datasets.push({
label: 'KRAKEN API calls',
data: [ count ],
backgroundColor: 'rgba(0, 0, 255, 0.2)',
borderColor: 'rgba(0, 0, 255, 0.5)'
})
} else krakenChart.data.datasets[0].data.push(count)
}
for (let count of _.values(krakenTimestampsErrorsPerMinute)) {
if (_.isNil(krakenChart.data.datasets[1])) {
krakenChart.data.datasets.push({
label: 'ERRORS',
data: [ count ],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 0.5)',
})
} else krakenChart.data.datasets[1].data.push(count)
}
krakenChart.update()
/* TMI CHART DATA */$
for (let label of _.map(_.keys(tmiTimestampsPerMinute), (o) => moment(parseInt(o, 10)).format('LTS'))) {
tmiChart.data.labels.push(label)
}
for (let count of _.values(tmiTimestampsPerMinute)) {
if (_.isNil(tmiChart.data.datasets[0])) {
tmiChart.data.datasets.push({
label: 'TMI API calls',
data: [ count ],
backgroundColor: 'rgba(0, 0, 255, 0.2)',
borderColor: 'rgba(0, 0, 255, 0.5)'
})
} else tmiChart.data.datasets[0].data.push(count)
}
for (let count of _.values(tmiTimestampsErrorsPerMinute)) {
if (_.isNil(tmiChart.data.datasets[1])) {
tmiChart.data.datasets.push({
label: 'ERRORS',
data: [ count ],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 0.5)',
})
} else tmiChart.data.datasets[1].data.push(count)
}
tmiChart.update()
/* UNOFFICIAL CHART DATA */$
for (let label of _.map(_.keys(unofficialTimestampsPerMinute), (o) => moment(parseInt(o, 10)).format('LTS'))) {
unofficialChart.data.labels.push(label)
}
for (let count of _.values(unofficialTimestampsPerMinute)) {
if (_.isNil(unofficialChart.data.datasets[0])) {
unofficialChart.data.datasets.push({
label: 'unofficial API calls',
data: [ count ],
backgroundColor: 'rgba(0, 0, 255, 0.2)',
borderColor: 'rgba(0, 0, 255, 0.5)'
})
} else unofficialChart.data.datasets[0].data.push(count)
}
for (let count of _.values(unofficialTimestampsErrorsPerMinute)) {
if (_.isNil(unofficialChart.data.datasets[1])) {
unofficialChart.data.datasets.push({
label: 'ERRORS',
data: [ count ],
backgroundColor: 'rgba(255, 0, 0, 0.2)',
borderColor: 'rgba(255, 0, 0, 0.5)',
})
} else unofficialChart.data.datasets[1].data.push(count)
}
unofficialChart.update()
})
</script>