Skip to content

Commit

Permalink
feat: adds basic telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdmike committed Sep 11, 2023
1 parent 7e13a1b commit da646a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 1 addition & 3 deletions src/middleware/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/stateMachines/unconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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<string, string>): void {
this.client.increment('rps.' + stat, value, sampleRate, tags)
public increment (stat: string, tags?: string[] | Record<string, string>): void {
this.client.increment('rps.' + stat, tags)
}

public decrement (stat: string, tags?: string[], sampleRate?: number): void {
Expand All @@ -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)
}
Expand Down

0 comments on commit da646a9

Please # to comment.