diff --git a/src/Index.ts b/src/Index.ts index 661bd9784..5068ccf9e 100644 --- a/src/Index.ts +++ b/src/Index.ts @@ -70,7 +70,7 @@ export const waitForSecretsManager = async function (secretsManager: ISecretMana } export const startItUp = (): void => { - statsD.increment('rps.startup', 1) + statsD.increment('startup') const configurator = new Configurator() log.silly(`WebSocket Cert Info ${JSON.stringify(Environment.Config)}`) const serverForEnterpriseAssistant: WSEnterpriseAssistantListener = new WSEnterpriseAssistantListener(new Logger('WSEnterpriseAssistantListener')) diff --git a/src/middleware/stats.ts b/src/middleware/stats.ts index 85ac3d708..cd4299236 100644 --- a/src/middleware/stats.ts +++ b/src/middleware/stats.ts @@ -16,10 +16,8 @@ export default function expressStatsdInit (): Handler { function sendStats (): void { // Status Code const statusCode: string = res.statusCode.toString() || 'unknown_status' - client.increment('status_code.' + statusCode) - - // Response Time const duration = new Date().getTime() - startTime + client.increment('request', { statusCode, method: req.method, url: req.baseUrl, duration: duration.toString() }) client.timing('response_time', duration) cleanup() diff --git a/src/stateMachines/unconfiguration.ts b/src/stateMachines/unconfiguration.ts index 521272374..a09d9f8ca 100644 --- a/src/stateMachines/unconfiguration.ts +++ b/src/stateMachines/unconfiguration.ts @@ -641,7 +641,7 @@ export class Unconfiguration { }, actions: { 'Metric Capture': (context, event) => { - statsD.increment('unconfiguration.success', 1) + statsD.increment('unconfiguration.success') }, 'Update CIRA Status': (context, event) => { devices[context.clientId].status.CIRAConnection = context.statusMessage @@ -653,7 +653,7 @@ export class Unconfiguration { devices[context.clientId].status.TLSConfiguration = '' devices[context.clientId].status.CIRAConnection = '' devices[context.clientId].status.Status = context.statusMessage - statsD.increment('unconfiguration.failure', 1) + statsD.increment('unconfiguration.failure') }, 'Reset Unauth Count': (context, event) => { devices[context.clientId].unauthCount = 0 }, 'Read WiFi Endpoint Settings Pull Response': this.readWiFiEndpointSettingsPullResponse.bind(this), diff --git a/src/utils/stats.ts b/src/utils/stats.ts index c7badd881..af4b36735 100644 --- a/src/utils/stats.ts +++ b/src/utils/stats.ts @@ -11,8 +11,8 @@ class StatsDClient { private constructor () { this.client = new StatsD({ - host: 'telegraf', - port: 8020, + host: process.env.TELEGRAF_HOST ?? 'localhost', + port: process.env.TELEGRAF_PORT ? parseInt(process.env.TELEGRAF_PORT, 10) : 8020, globalTags: { service: 'rps' }, errorHandler: this.errorHandler }) @@ -30,8 +30,8 @@ class StatsDClient { console.error('Error encountered in StatsD client:', error) } - public increment (stat: string, value?: number, sampleRate?: number, tags?: string[] | Record): void { - this.client.increment('rps.' + stat, value, sampleRate, tags) + public increment (stat: string, tags?: string[] | Record): void { + this.client.increment('rps.' + stat, tags) } public decrement (stat: string, tags?: string[], sampleRate?: number): void { @@ -42,6 +42,10 @@ class StatsDClient { this.client.timing('rps.' + stat, value) } + public event (title: string, text?: string, options?: any, tags?: string[]): void { + this.client.event(title, text, options, tags) + } + public close (callback?: (error?: Error) => void): void { this.client.close(callback) }