mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
prom: fix multi-machine
This commit is contained in:
1 parent
175609259a
commit
f030c32813
2 files changed
+4
-2
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import { hostname } from 'os';
|
||||||
import { AggregatorRegistry, metric } from 'prom-client';
|
import { AggregatorRegistry, metric } from 'prom-client';
|
||||||
import { Context, Handler, SystemModel } from 'hydrooj';
|
import { Context, Handler, SystemModel } from 'hydrooj';
|
||||||
import { createRegistry } from './metrics';
|
import { createRegistry } from './metrics';
|
||||||
@@ -39,10 +40,11 @@ class MetricsHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
export function apply(ctx: Context) {
|
||||||
|
if (process.env.HYDRO_CLI) return;
|
||||||
const registry = createRegistry(ctx);
|
const registry = createRegistry(ctx);
|
||||||
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
||||||
ctx.setInterval(async () => {
|
ctx.setInterval(async () => {
|
||||||
ctx.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
ctx.broadcast('metrics', `${hostname()}/${process.env.NODE_APP_INSTANCE}`, await registry.getMetricsAsJSON());
|
||||||
}, 5000 * (+SystemModel.get('prom-client.collect_rate') || 1));
|
}, 5000 * (+SystemModel.get('prom-client.collect_rate') || 1));
|
||||||
ctx.Route('metrics', '/metrics', MetricsHandler);
|
ctx.Route('metrics', '/metrics', MetricsHandler);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/prom-client",
|
"name": "@hydrooj/prom-client",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prom-client": "^14.1.0"
|
"prom-client": "^14.1.0"
|
||||||
|
|||||||
Reference in new issue
Block a user