diff options
author | Minteck <contact@minteck.org> | 2022-05-30 10:01:09 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-05-30 10:01:09 +0200 |
commit | e0b4c4e963afe23525b146883f70b6cb879c2297 (patch) | |
tree | 9d03521a721fd08e18a0ebf939870e51a6d56826 | |
parent | 1808fbb453a560952387e3add763b64eed1a03ab (diff) | |
download | vaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.tar.gz vaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.tar.bz2 vaportrail-statuspoller-e0b4c4e963afe23525b146883f70b6cb879c2297.zip |
Improve performance (especially for Windows Server)
-rw-r--r-- | .idea/.gitignore | 5 | ||||
-rw-r--r-- | .idea/discord.xml | 7 | ||||
-rw-r--r-- | .idea/modules.xml | 8 | ||||
-rw-r--r-- | .idea/vaportrail-statuspoller.iml | 12 | ||||
-rw-r--r-- | .idea/vcs.xml | 6 | ||||
-rw-r--r-- | index.ts | 52 | ||||
-rw-r--r-- | package-lock.json | 2 |
7 files changed, 77 insertions, 15 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="DiscordProjectSettings"> + <option name="show" value="PROJECT_FILES" /> + <option name="description" value="" /> + </component> +</project>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/vaportrail-statuspoller.iml" filepath="$PROJECT_DIR$/.idea/vaportrail-statuspoller.iml" /> + </modules> + </component> +</project>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/temp" /> + <excludeFolder url="file://$MODULE_DIR$/.tmp" /> + <excludeFolder url="file://$MODULE_DIR$/tmp" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project>
\ No newline at end of file @@ -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" |