Skip to content

Commit b822ef7

Browse files
committed
core: add balloonTask metric
1 parent 86740dd commit b822ef7

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

packages/server/handler/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ClientBallloonConnectHandler extends Handler {
9999
await this.ctx.db.client.updateOne({ id: params.cid }, { $set: { updateAt: new Date().getTime(), ip } });
100100
await this.ctx.db.balloon.update({ balloonid: { $in: balloons.map((b) => b.balloonid) } },
101101
{ $set: { receivedAt: new Date().getTime() } }, { multi: true });
102+
await this.ctx.parallel('balloon/sendTask', client._id, balloons.length);
102103
}
103104
}
104105

@@ -110,6 +111,7 @@ class ClientBalloonDoneHandler extends Handler {
110111
if (!balloon) throw new ValidationError('Balloon', params.bid, 'Balloon not found');
111112
await this.ctx.db.balloon.updateOne({ balloonid: +params.bid }, { $set: { printDone: 1, printDoneAt: new Date().getTime() } });
112113
if (!balloon.done) await this.ctx.fetcher.setBalloonDone(balloon.balloonid);
114+
await this.ctx.parallel('balloon/doneTask', client._id, 1);
113115
this.response.body = { code: 1 };
114116
logger.info(`Client ${client.name} connected, balloon task ${balloon.teamid}#${balloon.balloonid} completed.`);
115117
}

packages/server/service/fetcher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class DOMjudgeFetcher extends BasicFetcher {
148148
},
149149
}, { upsert: true });
150150
}
151+
await this.ctx.parallel('balloon/newTask', balloons.length);
151152
logger.debug(`Found ${balloons.length} balloons`);
152153
}
153154

@@ -234,6 +235,7 @@ class HydroFetcher extends BasicFetcher {
234235
},
235236
}, { upsert: true });
236237
}
238+
await this.ctx.parallel('balloon/newTask', balloons.length);
237239
logger.debug(`Found ${balloons.length} balloons`);
238240
}
239241

packages/server/utils/metrics.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ declare module 'cordis' {
1111
'print/newTask': () => void;
1212
'print/sendTask': (client: string) => void;
1313
'print/doneTask': (client: string, printer: string) => void;
14+
'balloon/newTask': (count: number) => void;
15+
'balloon/sendTask': (client: string, count: number) => void;
16+
'balloon/doneTask': (client: string, count: number) => void;
1417
}
1518
}
1619

@@ -44,6 +47,15 @@ export function createMetricsRegistry(ctx: Context) {
4447

4548
ctx.on('print/doneTask', (client, printer) => printTaskCounter.inc({ status: 'done', client, printer }));
4649

50+
const balloonTaskCounter = createMetric(Counter, 'xcpc_ballooncount', 'ballooncount', {
51+
labelNames: ['status', 'client'],
52+
});
53+
ctx.on('balloon/newTask', (count) => balloonTaskCounter.inc({ status: 'new' }, count));
54+
55+
ctx.on('balloon/sendTask', (client, count) => balloonTaskCounter.inc({ status: 'sent', client }, count));
56+
57+
ctx.on('balloon/doneTask', (client, count) => balloonTaskCounter.inc({ status: 'done', client }, count));
58+
4759
collectDefaultMetrics({ register: registry });
4860

4961
ctx.set('metrics', registry);

0 commit comments

Comments
 (0)