Skip to content

Commit

Permalink
feat(rabbitmq): Add more status stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Dec 16, 2019
1 parent 216c95b commit 0c4b5a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class IMClient extends Client {
public gatewayConnected: boolean;
public activityInterval: NodeJS.Timer;
public voiceConnections: LavaPlayerManager;
public eventsReceived: number;

private counts: {
cachedAt: Moment;
Expand Down Expand Up @@ -132,6 +133,7 @@ export class IMClient extends Client {
});

this.startedAt = moment();
this.eventsReceived = 0;
this.counts = {
cachedAt: moment.unix(0),
guilds: 0,
Expand Down Expand Up @@ -189,6 +191,7 @@ export class IMClient extends Client {
this.on('shardDisconnect', this.onDisconnect);
this.on('warn', this.onWarn);
this.on('error', this.onError);
this.on('rawWS', this.onRawWS);
}

private async onClientReady(): Promise<void> {
Expand Down Expand Up @@ -604,4 +607,8 @@ export class IMClient extends Client {
private async onError(error: Error) {
console.error('DISCORD ERROR:', error);
}

private async onRawWS() {
this.eventsReceived++;
}
}
2 changes: 2 additions & 0 deletions src/framework/commands/premium/tryPremium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export default class extends Command {
amount: 0,
maxGuilds: 1,
isFreeTier: true,
isPatreon: false,
isStaff: false,
validUntil: validUntil.toDate(),
memberId: message.author.id,
reason: ''
Expand Down
1 change: 1 addition & 0 deletions src/framework/services/PremiumService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class PremiumService {
maxGuilds,
isFreeTier: false,
isPatreon: true,
isStaff: false,
reason: ''
});
}
Expand Down
12 changes: 11 additions & 1 deletion src/framework/services/RabbitMq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export class RabbitMqService {
}

public async sendStatusToManager(err?: Error) {
const req = (this.client as any).requestHandler;
const queued = {} as any;
Object.keys(req.ratelimits).forEach(endpoint => (queued[endpoint] = req.ratelimits[endpoint]._queue.length));

await this.sendToManager({
id: 'status',
cmd: ShardCommand.STATUS,
Expand All @@ -160,7 +164,13 @@ export class RabbitMqService {
music: {
connections: this.client.music.getMusicConnectionGuildIds()
},
cache: this.getCacheSizes()
cache: this.getCacheSizes(),
events: {
received: this.client.eventsReceived
},
requests: {
queued
}
});
}

Expand Down

0 comments on commit 0c4b5a5

Please sign in to comment.