Skip to content

Commit

Permalink
feat(monitoring): report status of messaging and nlu (#11716)
Browse files Browse the repository at this point in the history
* feat(monitoring): report status of messaging and nlu

* check nlu is up

* pro

* update pro
  • Loading branch information
samuelmasse committed Apr 13, 2022
1 parent b4e6e42 commit a7b6b86
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions packages/bp/src/core/health/monitoring-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import axios from 'axios'
import * as sdk from 'botpress/sdk'
import { Metric, MonitoringMetrics } from 'common/monitoring'
import { injectable } from 'inversify'
import { makeNLUPassword } from 'common/nlu-token'
import { MessagingService } from 'core/messaging'
import { TYPES } from 'core/types'
import { inject, injectable, tagged } from 'inversify'
import { Redis } from 'ioredis'
import _ from 'lodash'
/**
Expand Down Expand Up @@ -62,6 +67,8 @@ export interface Status {
botpress: string
redis?: string
database?: string
messaging?: string
nlu?: string
}

export interface MonitoringService {
Expand All @@ -74,14 +81,46 @@ export interface MonitoringService {

@injectable()
export class CEMonitoringService implements MonitoringService {
constructor(
@inject(TYPES.Logger)
@tagged('name', 'Monitoring')
private logger: sdk.Logger,
@inject(TYPES.MessagingService) private messagingService: MessagingService
) {}

async start(): Promise<void> {}

stop(): void {}

async getStats(_dateFrom: number, _dateTo: number): Promise<string[]> {
return []
}

async getStatus(): Promise<Status> {
return { botpress: 'up' }
let messaging = 'n/a'
try {
await axios.get(`${this.messagingService.interactor.client.url}/status`)
messaging = 'up'
} catch (err) {
messaging = 'down'
}

let nlu = 'n/a'
try {
const nluEndpoint = process.NLU_ENDPOINT || `http://localhost:${process.NLU_PORT}`

await axios.get(`${nluEndpoint}/info`, {
headers: { Authorization: `Bearer ${makeNLUPassword()}` }
})

nlu = 'up'
} catch (err) {
nlu = 'down'
}

return { botpress: 'up', messaging, nlu }
}

getRedisFactory() {
return () => undefined
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bp/src/pro
Submodule pro updated from e10b68 to 193cdf

0 comments on commit a7b6b86

Please sign in to comment.