Skip to content

Commit

Permalink
fix(status): Clean up status report
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 26, 2020
1 parent 5c2a86d commit 3d6c857
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/framework/services/RabbitMq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ export class RabbitMqService extends IMService {
}

public async sendStatusToManager(err?: Error) {
const req = (this.client as any).requestHandler;

await this.sendToManager({
id: 'status',
cmd: ShardCommand.STATUS,
Expand All @@ -239,26 +237,10 @@ export class RabbitMqService extends IMService {
gateway: this.client.gatewayConnected,
guilds: this.client.guilds.size,
error: err ? err.message : null,
tracking: {
pendingGuilds: this.client.tracking.pendingGuilds.size,
initialPendingGuilds: this.client.tracking.initialPendingGuilds
},
music: {
connections: this.client.music.getMusicConnectionGuildIds()
},
tracking: this.getTrackingStatus(),
music: this.getMusicStatus(),
cache: this.getCacheSizes(),
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: Object.keys(req.ratelimits).reduce(
(acc, endpoint) => acc.concat([{ endpoint, count: req.ratelimits[endpoint]._queue.length as number }]),
[]
)
}
metrics: this.getMetrics()
});
}

Expand Down Expand Up @@ -480,6 +462,17 @@ export class RabbitMqService extends IMService {
}
}

private getTrackingStatus() {
return {
pendingGuilds: this.client.tracking.pendingGuilds.size,
initialPendingGuilds: this.client.tracking.initialPendingGuilds
};
}
private getMusicStatus() {
return {
connections: this.client.music.getMusicConnectionGuildIds()
};
}
private getCacheSizes() {
let channelCount = this.client.groupChannels.size + this.client.privateChannels.size;
let roleCount = 0;
Expand All @@ -505,4 +498,20 @@ export class RabbitMqService extends IMService {
messages: this.client.mod.getMessageCacheSize()
};
}
private getMetrics() {
const req = (this.client as any).requestHandler;

return {
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: Object.keys(req.ratelimits).reduce(
(acc, endpoint) => acc.concat([{ endpoint, count: req.ratelimits[endpoint]._queue.length as number }]),
[]
)
};
}
}

0 comments on commit 3d6c857

Please sign in to comment.