Skip to content

Commit

Permalink
feat(webserver): Add SystemRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed May 29, 2021
1 parent fe1fa88 commit efc46e6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions backend/lib/webserver/SystemRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const express = require("express");
const os = require("os");

class SystemRouter {
/**
*
* @param {object} options
*/
constructor(options) {
this.router = express.Router({mergeParams: true});

this.initRoutes();
}


initRoutes() {
this.router.get("/host/info", (req, res) => {
res.json({
hostname: os.hostname(),
arch: os.arch(),
mem: {
total: os.totalmem(),
free: os.freemem(),
valetudo_current: process.memoryUsage()?.rss,
valetudo_max: process.resourceUsage()?.maxRSS
},
uptime: os.uptime(),
load: os.loadavg(),
cpuCount: os.cpus().length
});
});

this.router.get("/runtime/info", (req, res) => {
res.json({
uptime: Math.floor(process.uptime()),
argv: process.argv,
execArgv: process.execArgv,
execPath: process.execPath,
uid: typeof process.getuid === "function" ? process.geteuid() : -1,
gid: typeof process.getegid === "function" ? process.getegid() : -1,
pid: process.pid,
versions: process.versions,
env: process.env
});
});
}

getRouter() {
return this.router;
}
}

module.exports = SystemRouter;
3 changes: 3 additions & 0 deletions backend/lib/webserver/WebServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ValetudoRouter = require("./ValetudoRouter");

const MiioValetudoRobot = require("../robots/MiioValetudoRobot");
const NTPClientRouter = require("./NTPClientRouter");
const SystemRouter = require("./SystemRouter");
const TimerRouter = require("./TimerRouter");

class WebServer {
Expand Down Expand Up @@ -89,6 +90,8 @@ class WebServer {

this.app.use("/api/v2/timers/", new TimerRouter({config: this.config, robot: this.robot}).getRouter());

this.app.use("/api/v2/system/", new SystemRouter({}).getRouter());

// TODO: This should point at a build
this.app.use(express.static(path.join(__dirname, "../../..", "frontend/lib")));

Expand Down

0 comments on commit efc46e6

Please sign in to comment.