diff --git a/src/routes/getStatus.ts b/src/routes/getStatus.ts index 704ffaf1..b4ea2546 100644 --- a/src/routes/getStatus.ts +++ b/src/routes/getStatus.ts @@ -1,6 +1,7 @@ import { db } from "../databases/databases"; import { Logger } from "../utils/logger"; import { Request, Response } from "express"; +import os from "os"; export async function getStatus(req: Request, res: Response): Promise { const startTime = Date.now(); @@ -14,8 +15,9 @@ export async function getStatus(req: Request, res: Response): Promise db: Number(dbVersion), startTime, processTime: Date.now() - startTime, + loadavg: os.loadavg().slice(1) // only return 5 & 15 minute load average }; - return value ? res.send(String(statusValues[value])) : res.send(statusValues); + return value ? res.send(JSON.stringify(statusValues[value])) : res.send(statusValues); } catch (err) { Logger.error(err as string); return res.sendStatus(500); diff --git a/test/cases/getStatus.ts b/test/cases/getStatus.ts index 5d175d72..b5154279 100644 --- a/test/cases/getStatus.ts +++ b/test/cases/getStatus.ts @@ -19,6 +19,7 @@ describe("getStatus", () => { assert.strictEqual(data.db, Number(dbVersion)); assert.ok(data.startTime); assert.ok(data.processTime >= 0); + assert.ok(data.loadavg.length == 2); done(); }) .catch(err => done(err)); @@ -74,4 +75,15 @@ describe("getStatus", () => { }) .catch(err => done(err)); }); + + it("Should be able to get loadavg only", (done) => { + client.get(`${endpoint}/loadavg`) + .then(res => { + assert.strictEqual(res.status, 200); + assert.ok(Number(res.data[0]) >= 0); + assert.ok(Number(res.data[1]) >= 0); + done(); + }) + .catch(err => done(err)); + }); });