actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
64 lines (63 loc) • 2.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = void 0;
const index_1 = require("./../index");
const path = require("path");
const fs = require("fs");
const packageJSON = JSON.parse(fs
.readFileSync(path.normalize(path.join(__dirname, "..", "..", "package.json")))
.toString());
// These values are probably good starting points, but you should expect to tweak them for your application
const maxMemoryAlloted = process.env.maxMemoryAlloted || 500;
const maxResqueQueueLength = process.env.maxResqueQueueLength || 1000;
class Status extends index_1.Action {
constructor() {
super();
this.name = "status";
this.description = "I will return some basic information about the API";
this.outputExample = {
id: "192.168.2.11",
actionheroVersion: "9.4.1",
uptime: 10469,
};
}
async run({ connection }) {
let nodeStatus = connection.localize("Node Healthy");
const problems = [];
const consumedMemoryMB = Math.round((process.memoryUsage().heapUsed / 1024 / 1024) * 100) / 100;
if (consumedMemoryMB > maxMemoryAlloted) {
nodeStatus = connection.localize("Unhealthy");
problems.push(connection.localize([
"Using more than {{maxMemoryAlloted}} MB of RAM/HEAP",
{ maxMemoryAlloted: maxMemoryAlloted },
]));
}
let resqueTotalQueueLength = 0;
const details = await index_1.task.details();
let length = 0;
Object.keys(details.queues).forEach((q) => {
length += details.queues[q].length;
});
resqueTotalQueueLength = length;
if (length > maxResqueQueueLength) {
nodeStatus = connection.localize("Node Unhealthy");
problems.push(connection.localize([
"Resque Queues over {{maxResqueQueueLength}} jobs",
{ maxResqueQueueLength: maxResqueQueueLength },
]));
}
return {
id: index_1.id,
actionheroVersion: index_1.actionheroVersion,
name: packageJSON.name,
description: packageJSON.description,
version: packageJSON.version,
uptime: new Date().getTime() - index_1.api.bootTime,
consumedMemoryMB,
resqueTotalQueueLength,
nodeStatus,
problems,
};
}
}
exports.Status = Status;