aboutsummaryrefslogtreecommitdiff
path: root/index.ts
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-30 10:01:09 +0200
committerMinteck <contact@minteck.org>2022-05-30 10:01:09 +0200
commite0b4c4e963afe23525b146883f70b6cb879c2297 (patch)
tree9d03521a721fd08e18a0ebf939870e51a6d56826 /index.ts
parent1808fbb453a560952387e3add763b64eed1a03ab (diff)
downloadvaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.tar.gz
vaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.tar.bz2
vaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.zip
Improve performance (especially for Windows Server)
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts52
1 files changed, 38 insertions, 14 deletions
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