-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 977 Bytes
/
server.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
const express = require('express');
const app = express();
const port = 3000;
let requestCount = 0;
// Serve files from the public directory
app.use(express.static('public'));
app.get('/', (req, res) => {
requestCount++;
res.send('Hello World!');
});
app.get('/time', (req, res) => {
requestCount++;
res.send({ time: new Date().toISOString() });
});
const os = require('os');
const pidusage = require('pidusage');
setInterval(() => {
// Memory stats
console.log('---------------------------------');
console.log('Total Requests:', requestCount);
console.log('Total Memory:', os.totalmem());
console.log('Free Memory:', os.freemem());
const memoryUsage = process.memoryUsage();
console.log('Node.js Process Memory Usage:', memoryUsage);
// CPU stats
pidusage(process.pid, (err, stats) => {
console.log('CPU Usage:', stats.cpu);
});
}, 5000);
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});