mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: ctx.setInterval support
This commit is contained in:
1 parent
6e04a1a8a1
commit
672c553f4c
3 files changed
+14
-11
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { AggregatorRegistry, metric } from 'prom-client';
|
||||
import * as system from 'hydrooj/src/model/system';
|
||||
import * as bus from 'hydrooj/src/service/bus';
|
||||
import { Handler, Route } from 'hydrooj/src/service/server';
|
||||
import { Handler } from 'hydrooj/src/service/server';
|
||||
import { registry } from './metrics';
|
||||
|
||||
declare module 'hydrooj/src/service/bus' {
|
||||
@@ -42,11 +42,10 @@ class MetricsHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
bus.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
||||
setInterval(async () => {
|
||||
bus.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
||||
}, 5000 * (+system.get('prom-client.collect_rate') || 1));
|
||||
|
||||
global.Hydro.handler.prom = () => {
|
||||
Route('metrics', '/metrics', MetricsHandler);
|
||||
};
|
||||
export function apply(ctx) {
|
||||
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
||||
ctx.setInterval(async () => {
|
||||
bus.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
||||
}, 5000 * (+system.get('prom-client.collect_rate') || 1));
|
||||
ctx.Route('metrics', '/metrics', MetricsHandler);
|
||||
}
|
||||
Reference in new issue
Block a user