mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
add loadAvg to status
This commit is contained in:
@@ -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();
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user