-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
72 lines (71 loc) · 2.36 KB
/
functions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* License: MIT
* LukeAz => https://github.com/LukeAz
*/
const fs = require('fs');
const express = require('express');
const WebSocket = require('ws');
const os = require('node-os-utils')
module.exports = {
initExpress: (PORT, HOST) => {
let app = express();
app.listen(PORT, HOST, () => {
console.log(`RaspStatApp listening at http://${HOST}:${PORT}`)
});
app.use(express.static('public'))
app.set('view engine', 'ejs');
return app;
},
initWebsocket: (PORT, HOST) => {
return new WebSocket.Server({port: PORT, host: HOST});
},
readTemperature: () => {
let temperature = Number(fs.readFileSync('/sys/class/thermal/thermal_zone0/temp', {encoding:'utf8', flag:'r'}));
return (isNaN(temperature)) ? false : (temperature/1000).toFixed(1);
},
getStaticInformation: async () => {
return {
sysInfo: await os.os.oos(),
cpuModel: await os.cpu.model(),
cpuThread: await os.cpu.count()
}
},
getInformation: async (maxTemp, temp) => {
let mem = await os.mem.info();
let disk = await os.drive.free();
let uptime = await os.os.uptime();
return {
maxTemperature: `${maxTemp}°C`,
freeMem: `${mem.freeMemMb} MB`,
totMem: `${mem.totalMemMb} MB`,
freeDisk: `${disk.freeGb} GB`,
totDisk: `${disk.totalGb} GB`,
uptime: `${Math.floor(uptime/(3600*24))} days, ${Math.floor(uptime % (3600*24) / 3600)} hours, ${Math.floor(uptime % 3600 / 60)} min, ${Math.floor(uptime % 60)} sec.`,
numProcess: await os.proc.totalProcesses(),
tempnow: {
value: temp,
symbol: "°C",
limit: 120,
text: "TEMP"
},
cpu: {
value: Math.round(await os.cpu.usage()),
symbol: "%",
limit: 100,
text: "CPU"
},
ram: {
value: Math.round(100-mem.freeMemPercentage),
symbol: "%",
limit: 100,
text: "RAM"
},
disk : {
value: Math.round(100-disk.freePercentage),
symbol: "%",
limit: 100,
text: "DISK"
}
}
}
}