From e0b4c4e963afe23525b146883f70b6cb879c2297 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 30 May 2022 10:01:09 +0200 Subject: Improve performance (especially for Windows Server) --- .idea/.gitignore | 5 ++++ .idea/discord.xml | 7 ++++++ .idea/modules.xml | 8 ++++++ .idea/vaportrail-statuspoller.iml | 12 +++++++++ .idea/vcs.xml | 6 +++++ index.ts | 52 ++++++++++++++++++++++++++++----------- package-lock.json | 2 +- 7 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/discord.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vaportrail-statuspoller.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ac77803 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vaportrail-statuspoller.iml b/.idea/vaportrail-statuspoller.iml new file mode 100644 index 0000000..0c8867d --- /dev/null +++ b/.idea/vaportrail-statuspoller.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/index.ts b/index.ts index 00d399b..fcc6846 100644 --- a/index.ts +++ b/index.ts @@ -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 diff --git a/package-lock.json b/package-lock.json index f5ef5ee..6c5d21d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "": { "name": "serverstatuspoller", "version": "1.0.0", - "license": "ISC", + "license": "MIT", "dependencies": { "express": "^4.18.1", "systeminformation": "^5.11.15" -- cgit