@@ -7,6 +7,11 @@ declare module 'cordis' {
7
7
interface Context {
8
8
metrics : Registry ;
9
9
}
10
+ interface Events {
11
+ 'print/newTask' : ( ) => void ;
12
+ 'print/sendTask' : ( ) => void ;
13
+ 'print/doneTask' : ( ) => void ;
14
+ }
10
15
}
11
16
12
17
export function createMetricsRegistry ( ctx : Context ) {
@@ -21,15 +26,24 @@ export function createMetricsRegistry(ctx: Context) {
21
26
}
22
27
23
28
createMetric ( Gauge , 'xcpc_machinecount' , 'machinecount' , {
29
+ labelNames : [ 'status' ] ,
24
30
async collect ( ) {
25
31
const machines = await ctx . db . monitor . find ( { } ) ;
26
32
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 ) ;
33
+ this . set ( { status : 'online' } , onlines . length ) ;
34
+ this . set ( { status : 'offline' } , machines . length - onlines . length ) ;
30
35
} ,
31
36
} ) ;
32
37
38
+ const printTaskCounter = createMetric ( Counter , 'xcpc_printcount' , 'printcount' , {
39
+ labelNames : [ 'status' ] ,
40
+ } ) ;
41
+ ctx . on ( 'print/newTask' , ( ) => printTaskCounter . inc ( { status : 'new' } ) ) ;
42
+
43
+ ctx . on ( 'print/sendTask' , ( ) => printTaskCounter . inc ( { status : 'sent' } ) ) ;
44
+
45
+ ctx . on ( 'print/doneTask' , ( ) => printTaskCounter . inc ( { status : 'done' } ) ) ;
46
+
33
47
collectDefaultMetrics ( { register : registry } ) ;
34
48
35
49
ctx . set ( 'metrics' , registry ) ;
0 commit comments