Skip to content

Commit

Permalink
feat(status): Add more stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco (Valandur) committed Dec 17, 2019
1 parent 3610038 commit ff878e5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
26 changes: 19 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ export class IMClient extends Client {
public gatewayConnected: boolean;
public activityInterval: NodeJS.Timer;
public voiceConnections: LavaPlayerManager;
public eventsRaised: number;
public warningsRaised: number;
public errorsRaised: number;
public stats: {
wsEvents: number;
wsWarnings: number;
wsErrors: number;
cmdProcessed: number;
cmdErrors: number;
cmdHttpErrors: Map<number, number>;
};

private counts: {
cachedAt: Moment;
Expand Down Expand Up @@ -135,7 +140,14 @@ export class IMClient extends Client {
});

this.startedAt = moment();
this.eventsRaised = 0;
this.stats = {
wsEvents: 0,
wsWarnings: 0,
wsErrors: 0,
cmdProcessed: 0,
cmdErrors: 0,
cmdHttpErrors: new Map()
};
this.counts = {
cachedAt: moment.unix(0),
guilds: 0,
Expand Down Expand Up @@ -604,15 +616,15 @@ export class IMClient extends Client {

private async onWarn(warn: string) {
console.error('DISCORD WARNING:', warn);
this.warningsRaised++;
this.stats.wsWarnings++;
}

private async onError(error: Error) {
console.error('DISCORD ERROR:', error);
this.errorsRaised++;
this.stats.wsErrors++;
}

private async onRawWS() {
this.eventsRaised++;
this.stats.wsEvents++;
}
}
8 changes: 8 additions & 0 deletions src/framework/services/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ export class CommandsService {
i++;
}

this.client.stats.cmdProcessed++;

// Run command
let error: any = null;
try {
Expand All @@ -467,6 +469,12 @@ export class CommandsService {
const execTime = Date.now() - start;

if (error) {
this.client.stats.cmdErrors++;
if (error.code) {
const num = this.client.stats.cmdHttpErrors.get(error.code) || 0;
this.client.stats.cmdHttpErrors.set(error.code, num + 1);
}

console.error(error);

withScope(scope => {
Expand Down
15 changes: 8 additions & 7 deletions src/framework/services/RabbitMq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ export class RabbitMqService {
connections: this.client.music.getMusicConnectionGuildIds()
},
cache: this.getCacheSizes(),
events: {
total: this.client.eventsRaised,
warnings: this.client.warningsRaised,
errors: this.client.errorsRaised
},
requests: {
queued
stats: {
wsEvents: this.client.stats.wsEvents,
wsWarnings: this.client.stats.wsWarnings,
wsErrors: this.client.stats.wsErrors,
cmdProcessed: this.client.stats.cmdProcessed,
cmdErrors: this.client.stats.cmdErrors,
cmdHttpErrors: [...this.client.stats.cmdHttpErrors.entries()].map(([code, count]) => ({ code, count })),
httpRequestsQueued: queued
}
});
}
Expand Down

0 comments on commit ff878e5

Please sign in to comment.