Skip to content

Commit d725c3d

Browse files
committed
core: add client label
1 parent bc41b4e commit d725c3d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/server/handler/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ClientPrintConnectHandler extends Handler {
6767
}
6868
this.response.body = { doc: code };
6969
if (params.printer && params.printer !== client.printer) this.response.body.setPrinter = client.printer;
70-
await this.ctx.parallel('print/sendTask');
70+
await this.ctx.parallel('print/sendTask', client._id);
7171
logger.info(`Client ${client.name} connected, print task ${code.tid}#${code._id} sent.`);
7272
await this.ctx.db.code.updateOne({ _id: code._id }, { $set: { printer: params.cid, receivedAt: new Date().getTime() } });
7373
}
@@ -81,7 +81,7 @@ class ClientPrintDoneHandler extends Handler {
8181
if (!code) throw new ValidationError('Code', null, 'Code not found');
8282
if (code.printer !== params.cid) throw new BadRequestError('Client', null, 'Client not match');
8383
await this.ctx.db.code.updateOne({ _id: params.tid }, { $set: { done: 1, doneAt: new Date().getTime() } });
84-
await this.ctx.parallel('print/doneTask');
84+
await this.ctx.parallel('print/doneTask', client._id);
8585
this.response.body = { code: 1 };
8686
logger.info(`Client ${client.name} connected, print task ${code.tid}#${code._id} completed.`);
8787
}

packages/server/utils/metrics.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ declare module 'cordis' {
99
}
1010
interface Events {
1111
'print/newTask': () => void;
12-
'print/sendTask': () => void;
13-
'print/doneTask': () => void;
12+
'print/sendTask': (client: string) => void;
13+
'print/doneTask': (client: string) => void;
1414
}
1515
}
1616

@@ -36,13 +36,13 @@ export function createMetricsRegistry(ctx: Context) {
3636
});
3737

3838
const printTaskCounter = createMetric(Counter, 'xcpc_printcount', 'printcount', {
39-
labelNames: ['status'],
39+
labelNames: ['status', 'client'],
4040
});
4141
ctx.on('print/newTask', () => printTaskCounter.inc({ status: 'new' }));
4242

43-
ctx.on('print/sendTask', () => printTaskCounter.inc({ status: 'sent' }));
43+
ctx.on('print/sendTask', (client) => printTaskCounter.inc({ status: 'sent', client }));
4444

45-
ctx.on('print/doneTask', () => printTaskCounter.inc({ status: 'done' }));
45+
ctx.on('print/doneTask', (client) => printTaskCounter.inc({ status: 'done', client }));
4646

4747
collectDefaultMetrics({ register: registry });
4848

0 commit comments

Comments
 (0)