prom: fix gauge typings

This commit is contained in:
undefined committed 2022-08-20 18:11:01 +08:00
1 parent 43f5f0c9c3
commit 55cee2ef1c
4 files changed
+7 -6

No files matched your search

+1 -1
View File
@@ -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",
+2 -1
View File
@@ -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);
} }
+3 -3
View File
@@ -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 -1
View File
@@ -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"
} }