pandora-metrics
Version:
## Overview
52 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const debug = require('debug')('pandora:metrics:resource:health');
class HealthResource {
constructor(endPointService) {
this.prefix = '/health';
this.endPointService = endPointService;
}
route(router) {
const healthEndPoint = this.endPointService.getEndPoint('health');
router.get('/', async (ctx, next) => {
let appName = ctx.query['appName'];
debug(`in router and health by ${appName}`);
let queryResults = await healthEndPoint.invoke({ appName });
if (appName) {
let healthRet = { status: 'UP' };
for (let queryResult of queryResults) {
healthRet[queryResult.key] = { status: queryResult.data };
if (queryResult.data === 'DOWN') {
healthRet.status = 'DOWN';
}
}
try {
ctx.ok(healthRet);
}
catch (err) {
ctx.fail(err.message);
}
}
else {
let healthRet = {};
for (let appName in queryResults) {
healthRet[appName] = { status: 'UP' };
for (let queryResult of queryResults[appName]) {
healthRet[appName][queryResult.key] = { status: queryResult.data };
if (queryResult.data === 'DOWN') {
healthRet[appName].status = 'DOWN';
}
}
}
try {
ctx.ok(healthRet);
}
catch (err) {
ctx.fail(err.message);
}
}
});
}
}
exports.HealthResource = HealthResource;
//# sourceMappingURL=HealthResource.js.map