-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
40 lines (31 loc) · 931 Bytes
/
index.js
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
const express = require('express');
const path = require('path');
const app = express();
const port = 80;
let rcount = {};
const maxpath = 10;
app.use((req, res, next) => {
const path = req.path;
rcount[path] = (rcount[path] || 0) + 1;
next();
});
app.use(express.static(path.join(__dirname, 'asset')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'html', 'index.html'));
});
app.get('/api/stats', (req, res) => {
const rvlnd = Object.entries(rcount)
.sort(([, countA], [, countB]) => countB - countA)
.slice(0, maxpath);
const toppath = rvlnd.map(([path, count]) => ({ path, requests: count }));
res.json({
totalrps: Object.values(rcount).reduce((acc, count) => acc + count, 0),
toppath: toppath,
});
});
setInterval(() => {
rcount = {};
}, 1000);
app.listen(port, () => {
console.log(`dstat is running. - @Rvlnddddd`);
});