-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (41 loc) · 1.07 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
const osu = require('node-os-utils');
const cpu = osu.cpu;
const drive = osu.drive;
const mem = osu.mem;
const rp = require("request-promise");
const config = require("./config.json");
const moment = require("moment");
async function run(){
try{
let total_cpu = cpu.count();
let usage_cpu = await cpu.usage(5000);
const disk = await drive.info();
let mem_info = await mem.info();
await rp({
uri: `${config.server}/api/listen/resources`,
method: "PUT",
body: {
total_cpu: total_cpu,
usage_cpu_percentage: usage_cpu,
total_disk: disk.totalGb,
usage_disk: disk.usedGb,
total_memory: mem_info.totalMemMb,
usage_memory: mem_info.usedMemMb,
ip: osu.os.ip(),
name: osu.os.hostname(),
type: config.type
},
json: true
})
console.log("Update Done", moment().utcOffset(+7).format("HH:mm:ss YYYY-MM-DD"))
}
catch(e){
console.log(e.message);
}
}
async function setIntervalAndExecute(fn, t) {
console.log("Start send resource of system");
await fn();
return(setInterval(fn, t));
}
setIntervalAndExecute(run, 1 * 60 * 1000)