diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 6a14285..50aa25e 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -362,6 +362,10 @@ export function isAnalyticReady(): boolean { return analyticsService.ready; } +export function analyticsLastAlive(): Date { + return analyticsService.lastAlive; +} + export async function getActiveWebhooks() { const analyticUnits = await AnalyticUnit.findMany({ alert: true }); return analyticUnits.map(analyticUnit => analyticUnit.id); diff --git a/server/src/index.ts b/server/src/index.ts index 970400f..0f634aa 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -46,7 +46,11 @@ rootRouter.get('/', async (ctx) => { ctx.response.body = { server: 'OK', - analyticsReady: AnalyticsController.isAnalyticReady(), + analytics: { + ready: AnalyticsController.isAnalyticReady(), + lastAlive: AnalyticsController.analyticsLastAlive(), + tasksQueueLength: AnalyticsController.getQueueLength() + }, nodeVersion: process.version, packageVersion: PACKAGE_VERSION, npmUserAgent: process.env.npm_config_user_agent, @@ -55,7 +59,7 @@ rootRouter.get('/', async (ctx) => { serverPort: HASTIC_PORT, git: GIT_INFO, activeWebhooks: activeWebhooks.length, - queueLength: AnalyticsController.getQueueLength() + timestamp: new Date(Date.now()) }; }); diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index dcb6fbd..c0b3da0 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -17,6 +17,7 @@ export class AnalyticsService { private _alertService = new AlertService(); private _requester: any; private _ready: boolean = false; + private _lastAlive: Date = null; private _pingResponded = false; private _zmqConnectionString: string = null; private _ipcPath: string = null; @@ -82,6 +83,7 @@ export class AnalyticsService { } public get ready(): boolean { return this._ready; } + public get lastAlive(): Date { return this._lastAlive; } private async _init() { this._requester = zmq.socket('pair'); @@ -197,6 +199,7 @@ export class AnalyticsService { let text = data.toString(); if(text === 'PONG') { this._pingResponded = true; + this._lastAlive = new Date(Date.now()); if(!this._ready) { this._ready = true; this._onAnalyticsUp();