Skip to content

Commit d3007a5

Browse files
committed
core: add different type machine count
1 parent 20eb28a commit d3007a5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/server/utils/metrics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export function createMetricsRegistry(ctx: Context) {
2222

2323
createMetric(Gauge, 'xcpc_machinecount', 'machinecount', {
2424
async collect() {
25-
this.set({}, await ctx.db.monitor.count({ updateAt: { $gt: new Date().getTime() - 120 * 1000 } }));
25+
const machines = await ctx.db.monitor.find({});
26+
const onlines = machines.filter((m) => m.updateAt > new Date().getTime() - 1000 * 60);
27+
this.set({ type: 'total' }, machines.length);
28+
this.set({ type: 'online' }, onlines.length);
29+
this.set({ type: 'offline' }, machines.length - onlines.length);
2630
},
2731
});
2832

0 commit comments

Comments
 (0)