diff options
Diffstat (limited to 'index.ts')
-rw-r--r-- | index.ts | 52 |
1 files changed, 38 insertions, 14 deletions
@@ -1,19 +1,31 @@ import express from "express"; import si from "systeminformation"; +import nodeOS from "os"; const app = express(); +const PORT = 52937; -app.get("/json", async (req, res) => { +async function refresh() { // Gives the info for this server - let cpu = await si.cpu(); - let cpuSpeed = await si.cpuCurrentSpeed(); - let temp = await si.cpuTemperature(); - let memory = await si.mem(); - let os = await si.osInfo(); - let time = si.time(); - let load = await si.currentLoad(); - let processes = await si.processes(); + global.cpu = await si.cpu(); + global.cpuSpeed = await si.cpuCurrentSpeed(); + global.temp = await si.cpuTemperature(); + global.memory = await si.mem(); + global.os = await si.osInfo(); + global.time = si.time(); + global.load = await si.currentLoad(); + global.processes = await si.processes(); +} +app.get("/json", async (req, res) => { + let cpu = global.cpu; + let cpuSpeed = global.cpuSpeed; + let temp = global.temp; + let memory = global.memory; + let os = global.os; + let time = global.time; + let load = global.load; + let processes = global.processes; let uptime = parseInt(time.uptime) * 1000; res.json({ @@ -44,14 +56,26 @@ app.get("/json", async (req, res) => { total: memory.total }, os: { - name: os.distro, + name: nodeOS.platform() === "win32" + ? os.platform + : os.distro, version: os.release }, uptime: uptime, - version: "1.0.0" + version: "1.1.0" }); }); -app.listen(52937, () => { - console.log("listening!"); -});
\ No newline at end of file +console.log("Waiting for initial data processing..."); +refresh().then(() => { + app.listen(PORT, () => { + console.log("Listening on port " + PORT + "!"); + setInterval(async () => { + await refresh(); + }, ( + nodeOS.platform() === "win32" + ? 300000 + : 3000 + )) + }); +})
\ No newline at end of file |