prom: fix gauge typings

pull/419/head
undefined 2 years ago
parent 43f5f0c9c3
commit 55cee2ef1c

@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.15.17", "version": "3.15.18",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",

@ -416,9 +416,10 @@ export function Connection(
}; };
} }
conn.onclose = () => { conn.onclose = () => {
h.cleanup?.(args);
bus.emit('connection/close', h); bus.emit('connection/close', h);
h.cleanup?.(args);
}; };
bus.emit('connection/active', h);
} catch (e) { } catch (e) {
await h.onerror(e); await h.onerror(e);
} }

@ -8,7 +8,7 @@ export const registry = new Registry();
registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE }); registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE });
function createMetric<Q extends string, T extends (new (a: any) => Metric<Q>)>( function createMetric<Q extends string, T extends (new (a: any) => Metric<Q>)>(
C: T, name: string, help: string, extra?: T extends new (a: infer R) => any ? Partial<R> : never, C: T, name: string, help: string, extra?: T extends new (a: infer R) => any ? Partial<R> : never,
): T extends new (a) => Counter<Q> ? Counter<Q> : T extends new (a) => Gauge<Q> ? Gauge<Q> : Metric<Q> { ): T extends (new (a) => Gauge<Q>) ? Gauge<Q> : T extends (new (a) => Counter<Q>) ? Counter<Q> : Metric<Q> {
const metric = new C({ name, help, ...(extra || {}) }); const metric = new C({ name, help, ...(extra || {}) });
registry.registerMetric(metric); registry.registerMetric(metric);
return metric as any; return metric as any;
@ -38,11 +38,11 @@ bus.on('handler/after/ProblemSubmit', (that) => {
const connectionGauge = createMetric(Gauge, 'hydro_connection', 'connectioncount', { const connectionGauge = createMetric(Gauge, 'hydro_connection', 'connectioncount', {
labelNames: ['domainId'], labelNames: ['domainId'],
}); });
bus.on('connection/create', (h) => { bus.on('connection/active', (h) => {
connectionGauge.inc({ domainId: h.args.domainId }); connectionGauge.inc({ domainId: h.args.domainId });
}); });
bus.on('connection/close', (h) => { bus.on('connection/close', (h) => {
connectionGauge.inc({ domainId: h.args.domainId }, -1); connectionGauge.dec({ domainId: h.args.domainId });
}); });
const taskColl = db.collection('task'); const taskColl = db.collection('task');

@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/prom-client", "name": "@hydrooj/prom-client",
"version": "0.0.2", "version": "0.0.3",
"dependencies": { "dependencies": {
"prom-client": "^14.0.1" "prom-client": "^14.0.1"
} }

Loading…
Cancel
Save