Skip to content

Commit

Permalink
Merge pull request #386 from mchangrh/more-stats
Browse files Browse the repository at this point in the history
add loadAvg to status
  • Loading branch information
ajayyy authored Oct 27, 2021
2 parents 9353697 + 109578a commit 393027c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/routes/getStatus.ts
Original file line number Diff line number Diff line change
@@ -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<Response> {
const startTime = Date.now();
Expand All @@ -14,8 +15,9 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
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);
Expand Down
12 changes: 12 additions & 0 deletions test/cases/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
});
});

0 comments on commit 393027c

Please sign in to comment.