@@ -34,11 +34,14 @@ function structureOutput(input) {
34
34
module . exports = ( registry , config = { } ) => {
35
35
const registers = registry ? [ registry ] : undefined ;
36
36
const namePrefix = config . prefix ? config . prefix : '' ;
37
+ const labels = config . labels ? config . labels : { } ;
38
+ const labelNames = Object . keys ( labels ) ;
37
39
38
40
const residentMemGauge = new Gauge ( {
39
41
name : namePrefix + PROCESS_RESIDENT_MEMORY ,
40
42
help : 'Resident memory size in bytes.' ,
41
43
registers,
44
+ labelNames,
42
45
// Use this one metric's `collect` to set all metrics' values.
43
46
collect ( ) {
44
47
try {
@@ -51,9 +54,9 @@ module.exports = (registry, config = {}) => {
51
54
const stat = fs . readFileSync ( '/proc/self/status' , 'utf8' ) ;
52
55
const structuredOutput = structureOutput ( stat ) ;
53
56
54
- residentMemGauge . set ( structuredOutput . VmRSS ) ;
55
- virtualMemGauge . set ( structuredOutput . VmSize ) ;
56
- heapSizeMemGauge . set ( structuredOutput . VmData ) ;
57
+ residentMemGauge . set ( labels , structuredOutput . VmRSS ) ;
58
+ virtualMemGauge . set ( labels , structuredOutput . VmSize ) ;
59
+ heapSizeMemGauge . set ( labels , structuredOutput . VmData ) ;
57
60
} catch {
58
61
// noop
59
62
}
@@ -63,11 +66,13 @@ module.exports = (registry, config = {}) => {
63
66
name : namePrefix + PROCESS_VIRTUAL_MEMORY ,
64
67
help : 'Virtual memory size in bytes.' ,
65
68
registers,
69
+ labelNames,
66
70
} ) ;
67
71
const heapSizeMemGauge = new Gauge ( {
68
72
name : namePrefix + PROCESS_HEAP ,
69
73
help : 'Process heap size in bytes.' ,
70
74
registers,
75
+ labelNames,
71
76
} ) ;
72
77
} ;
73
78
0 commit comments