-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
139 lines (117 loc) · 4.15 KB
/
server.js
File metadata and controls
139 lines (117 loc) · 4.15 KB
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
require('dotenv').config()
const express = require('express')
const router = express.Router()
const path = require('path')
const app = express()
const busboy = require('connect-busboy')
const bodyParser = require('body-parser')
const favicon = require('serve-favicon')
const os = require('os');
const osu = require('node-os-utils')
const cpuosu = osu.cpu
const ping = require('ping');
const si = require('systeminformation');
// Variables
var cputemp = null;
var networktemp = {};
var networkhosts = [process.env.ROUTER, 'google.com', 'espanastore.es'];
var static_data = [[],[],[],[],[],[],[],[]];
var dynamic_data = [{id: 1, freeram: null}];
// Port
app.listen(process.env.PORT);
console.log("Listening on port " + process.env.PORT)
// USE
app.use(express.json({limit: '20mb'}));
app.use(express.urlencoded({limit: '20mb', extended: true}));
app.use(bodyParser.urlencoded());
app.use(bodyParser.json({limit: '20mb'}));
app.use(bodyParser.urlencoded({limit: '20mb', extended: true}));
app.set('view-engine', 'ejs')
app.use(favicon(__dirname + '/img/logo/logo-icon.ico'));
app.use(busboy());
// Get static data
si.cpu().then(data => {
static_data[0][0] = data.manufacturer,
static_data[0][1] = data.brand,
static_data[0][2] = data.socket,
static_data[0][3] = data.speed,
static_data[0][4] = data.cores
}).catch(error => console.error(error));
si.system().then(data => {
static_data[1][0] = data.manufacturer,
static_data[1][1] = data.model
}).catch(error => console.error(error));
si.bios().then(data => {
static_data[1][2] = data.vendor,
static_data[1][3] = data.version,
static_data[1][4] = data.releaseDate
}).catch(error => console.error(error));
si.memLayout().then(data => {
static_data[2].push(data)
}).catch(error => console.error(error));
si.osInfo().then(data => {
static_data[1][5] = data.uefi,
static_data[3][0] = data.distro,
static_data[3][1] = data.release,
static_data[3][2] = data.hostname
}).catch(error => console.error(error));
si.battery().then(data => {
static_data[4][0] = data.model,
static_data[4][1] = data.manufacturer,
static_data[4][2] = data.acConnected,
static_data[4][3] = data.percent,
static_data[4][4] = data.maxCapacity,
static_data[4][5] = data.hasBattery
}).catch(error => console.error(error));
si.diskLayout().then(data => {
static_data[5].push([data[0].type, data[0].name, data[0].vendor, data[0].size, data[0].interfaceType])
}).catch(error => console.error(error));
si.graphics().then(data => {
static_data[6].push([data.controllers])
}).catch(error => console.error(error));
si.networkGatewayDefault().then(data => {
static_data[7][0] = data
}).catch(error => console.error(error));
si.networkInterfaceDefault().then(data => {
static_data[7][1] = data
}).catch(error => console.error(error));
/*
--> ADD returns wifi info (ssid, quality etc)
si.wifiNetworks()
.then(data => console.log(data))
.catch(error => console.error(error));
--> ADD rj42 & wifi (filter only wifi and Ethernet)
si.networkInterfaceDefault() --> wifi
.then(data => console.log(data))
.catch(error => console.error(error));
--> ADD in specification smalles divs with each storage unit C:/D: DVD local etc
si.blockDevices()
.then(data => console.log(data))
.catch(error => console.error(error));
--> ADD relation with above blockDevices (just add in same array), match D: or C: with the above, this one provides available space
si.fsSize()
.then(data => console.log(data))
.catch(error => console.error(error));
*/
// Updates
var intervalId = setInterval(function() {
cpuosu.usage().then(cpuPercentage => {
cputemp = cpuPercentage;
})
networkhosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
networktemp[host] = [isAlive];
});
});
dynamic_data = [{id: 1, freeram: (os.freemem() / 1000 / 1000 / 1000).toFixed(2), cpusage: cputemp, network: JSON.stringify(networktemp), uptime: os.uptime()}];
}, process.env.SPEED);
// Get
app.get(['/', '/index'], function (req, res) {
res.render('index.ejs', { staticdata: JSON.stringify(static_data)}),
app.use(express.static(__dirname + '/css')),
app.use(express.static(__dirname + '/img')),
app.use(express.static(__dirname + '/js'))
})
app.get('/api/nodemonitor', (req, res) => {
res.send(dynamic_data);
});