-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (52 loc) · 1.89 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var express = require('express')
var app = express()
app.use(express.static('public'))
app.get('/stats/:startTime/:endTime/:duration', function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(generateResponse(Number(req.params.startTime), Number(req.params.endTime), Number(req.params.duration), 'server1665'))
})
app.listen(3000, function () {
console.log('Server monitoring app listening on port 3000!')
})
function generateResponse(startTime, endTime, duration, serverID) {
function getRandomNumber(upperBound) {
return Math.floor(Math.random() * upperBound);
}
var records = [],
memUpperBound = 40000,
throughputUpperBound = 20000,
packetUpperBound = 1000,
errorUpperBound = 5;
for (var ts = startTime; ts < endTime; ts += duration) {
records.push({
timestamp: (new Date(ts)).toISOString(),
memory_usage: getRandomNumber(memUpperBound),
memory_available: getRandomNumber(memUpperBound),
cpu_usage: Math.random().toFixed(2),
network_throughput: {
"in": getRandomNumber(throughputUpperBound),
out: getRandomNumber(throughputUpperBound)
},
network_packet: {
"in": getRandomNumber(packetUpperBound),
out: getRandomNumber(packetUpperBound)
},
errors: {
system: getRandomNumber(errorUpperBound),
sensor: getRandomNumber(errorUpperBound),
component: getRandomNumber(errorUpperBound)
}
});
}
return {
header: {
target_name: serverID,
time_range: {
start: new Date(startTime).toISOString(),
end: new Date(endTime).toISOString()
},
recordCount: records.length
},
data: records
};
}