This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (46 loc) · 1.44 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
const express = require('express');
const app = express();
const os = require('os');
const si = require('systeminformation');
const port = 80
const server = app.listen(port, function() {
console.log(`API is now running on port ${port}`);
});
const router = express.Router();
app.get('/os', function (req, res) {
const gbU = os.totalmem / 1000000000;
const gbR = Math.round(gbU);
const freegbU = os.freemem / 1000000000;
const freegbR = Math.round(freegbU);
const freegbF = gbR - freegbR;
const hours = os.uptime / 1440;
const sysuptime = Math.floor(hours);
const days = hours / 24;
const sysuptimeDays = Math.round(days);
const thisObject = {
name: os.hostname(),
type: os.type(),
info: {
name: si.osInfo().then(d => d.distro),
hostname: os.hostname(),
type: os.type(),
},
cpu: {
name: os.cpus()[0].model,
cores: os.cpus().length,
usage: process.cpuUsage().user
},
memory: `${freegbF}GB/${gbR}GB`,
uptime: `${sysuptimeDays} days | ${sysuptime} total hours`
}
res.status(200).send(thisObject);
});
/*app.post('/node/:process', function (req, res) {
const { execFile } = require('child_process');
const child = execFile('node', [`${req.body}`], (error, stdout, stderr) => {
if (error) {
res.status(400).send(error);
}
res.status(400).send(stdout);
});
})*/