From ac15686b47e47c74a91f9773b408a404aa3a22ef Mon Sep 17 00:00:00 2001 From: Michael C Date: Wed, 20 Oct 2021 00:16:27 -0400 Subject: [PATCH 1/2] add loadAvg to status --- src/routes/getStatus.ts | 4 +++- test/cases/getStatus.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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..10b10db1 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,16 @@ describe("getStatus", () => { }) .catch(err => done(err)); }); + + it("Should be able to get loadavg only", (done) => { + client.get(`${endpoint}/loadavg`) + .then(res => { + console.log(res.data); + assert.strictEqual(res.status, 200); + assert.ok(Number(res.data[0]) >= 0); + assert.ok(Number(res.data[1]) >= 0); + done(); + }) + .catch(err => done(err)); + }); }); From 109578a3eda14418c9af8fbba96f14a5e447c086 Mon Sep 17 00:00:00 2001 From: Michael C Date: Wed, 20 Oct 2021 00:59:08 -0400 Subject: [PATCH 2/2] remove extra console.log lines --- test/cases/getStatus.ts | 1 - test/cases/setUsername.ts | 1 - test/cases/voteOnSponsorTime.ts | 2 -- 3 files changed, 4 deletions(-) diff --git a/test/cases/getStatus.ts b/test/cases/getStatus.ts index 10b10db1..b5154279 100644 --- a/test/cases/getStatus.ts +++ b/test/cases/getStatus.ts @@ -79,7 +79,6 @@ describe("getStatus", () => { it("Should be able to get loadavg only", (done) => { client.get(`${endpoint}/loadavg`) .then(res => { - console.log(res.data); assert.strictEqual(res.status, 200); assert.ok(Number(res.data[0]) >= 0); assert.ok(Number(res.data[1]) >= 0); diff --git a/test/cases/setUsername.ts b/test/cases/setUsername.ts index f1f3f15e..89af032c 100644 --- a/test/cases/setUsername.ts +++ b/test/cases/setUsername.ts @@ -92,7 +92,6 @@ describe("setUsername", () => { it("Should be able to set username that has never been set", (done) => { postSetUserName(user00PrivateUserID, username00) .then(async res => { - console.log(res.data); const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID)); assert.strictEqual(res.status, 200); assert.strictEqual(usernameInfo.userName, username00); diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 377c7d2c..fcb823db 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -299,7 +299,6 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category); assert.strictEqual(row.category, category); done(); }) @@ -314,7 +313,6 @@ describe("voteOnSponsorTime", () => { .then(async res => { assert.strictEqual(res.status, 200); const row = await getSegmentCategory(UUID); - console.log(row.category); assert.strictEqual(row.category, "intro"); done(); })