Browse Source

analytics in status in child-node & status last alive & timestamp

pull/1/head
Coin de Gamma 6 years ago
parent
commit
d9f27944a2
  1. 4
      server/src/controllers/analytics_controller.ts
  2. 8
      server/src/index.ts
  3. 3
      server/src/services/analytics_service.ts

4
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);

8
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())
};
});

3
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();

Loading…
Cancel
Save