23
23
* </pre>
24
24
* Example metrics being exported:
25
25
* <pre>
26
- * jvm_memory_used{area="heap} 2000000
27
- * jvm_memory_limit{area="nonheap"} 200000
28
- * jvm_memory_pool_used{pool="PS-Eden-Space"} 2000
26
+ * jvm_memory_bytes_used{area="heap"} 2000000
27
+ * jvm_memory_bytes_committed{area="nonheap"} 200000
28
+ * jvm_memory_bytes_max{area="nonheap"} 2000000
29
+ * jvm_memory_pool_bytes_used{pool="PS Eden Space"} 2000
29
30
* </pre>
30
31
*/
31
32
public class MemoryPoolsExports extends Collector {
32
- private static final Pattern WHITESPACE = Pattern .compile ("[\\ s]+" );
33
- static final String MEMORY_USED_METRIC = "jvm_memory_used" ;
34
- static final String MEMORY_LIMIT_METRIC = "jvm_memory_limit" ;
35
- static final String POOLS_USED_METRIC = "jvm_memory_pool_used" ;
36
- static final String POOLS_LIMIT_METRIC = "jvm_memory_pool_limit" ;
37
-
38
- private static final List <String > MEMORY_LABEL_NAMES = Arrays .asList ("area" );
39
- private static final List <String > MEMORY_HEAP_LABEL = Arrays .asList ("heap" );
40
- private static final List <String > MEMORY_NONHEAP_LABEL = Arrays .asList ("nonheap" );
41
-
42
- private static final List <String > POOLS_LABEL_NAMES = Arrays .asList ("pool" );
43
-
44
- private final HashMap <MemoryPoolMXBean , List <String >> poolLabelValues = new HashMap <MemoryPoolMXBean , List <String >>();
45
33
private final MemoryMXBean memoryBean ;
46
34
private final List <MemoryPoolMXBean > poolBeans ;
47
35
@@ -55,12 +43,6 @@ public MemoryPoolsExports(MemoryMXBean memoryBean,
55
43
List <MemoryPoolMXBean > poolBeans ) {
56
44
this .memoryBean = memoryBean ;
57
45
this .poolBeans = poolBeans ;
58
- for (final MemoryPoolMXBean pool : poolBeans ) {
59
- if (!poolLabelValues .containsKey (pool )) {
60
- String gcName = WHITESPACE .matcher (pool .getName ()).replaceAll ("-" );
61
- poolLabelValues .put (pool , Arrays .asList (gcName ));
62
- }
63
- }
64
46
}
65
47
66
48
void addMemoryAreaMetrics (List <MetricFamilySamples > sampleFamilies ) {
@@ -69,74 +51,107 @@ void addMemoryAreaMetrics(List<MetricFamilySamples> sampleFamilies) {
69
51
ArrayList <MetricFamilySamples .Sample > usedSamples = new ArrayList <MetricFamilySamples .Sample >();
70
52
usedSamples .add (
71
53
new MetricFamilySamples .Sample (
72
- MEMORY_USED_METRIC ,
73
- MEMORY_LABEL_NAMES ,
74
- MEMORY_HEAP_LABEL ,
54
+ "jvm_memory_bytes_used" ,
55
+ Arrays . asList ( "area" ) ,
56
+ Arrays . asList ( "heap" ) ,
75
57
heapUsage .getUsed ()));
76
58
usedSamples .add (
77
59
new MetricFamilySamples .Sample (
78
- MEMORY_USED_METRIC ,
79
- MEMORY_LABEL_NAMES ,
80
- MEMORY_NONHEAP_LABEL ,
60
+ "jvm_memory_bytes_used" ,
61
+ Arrays . asList ( "area" ) ,
62
+ Arrays . asList ( "nonheap" ) ,
81
63
nonHeapUsage .getUsed ()));
82
64
sampleFamilies .add (
83
65
new MetricFamilySamples (
84
- MEMORY_USED_METRIC ,
66
+ "jvm_memory_bytes_used" ,
85
67
Type .GAUGE ,
86
- "Used bytes of a given JVM memory area (heap, nonheap) ." ,
68
+ "Used bytes of a given JVM memory area." ,
87
69
usedSamples ));
88
- ArrayList <MetricFamilySamples .Sample > limitSamples = new ArrayList <MetricFamilySamples .Sample >();
89
- limitSamples .add (
70
+ ArrayList <MetricFamilySamples .Sample > committedSamples = new ArrayList <MetricFamilySamples .Sample >();
71
+ committedSamples .add (
90
72
new MetricFamilySamples .Sample (
91
- MEMORY_LIMIT_METRIC ,
92
- MEMORY_LABEL_NAMES ,
93
- MEMORY_HEAP_LABEL ,
94
- heapUsage .getMax () == - 1 ? heapUsage . getMax () : heapUsage . getCommitted ()));
95
- limitSamples .add (
73
+ "jvm_memory_bytes_committed" ,
74
+ Arrays . asList ( "area" ) ,
75
+ Arrays . asList ( "heap" ) ,
76
+ heapUsage .getCommitted ()));
77
+ committedSamples .add (
96
78
new MetricFamilySamples .Sample (
97
- MEMORY_LIMIT_METRIC ,
98
- MEMORY_LABEL_NAMES ,
99
- MEMORY_NONHEAP_LABEL ,
100
- nonHeapUsage .getMax () == - 1 ? nonHeapUsage . getMax () : nonHeapUsage . getCommitted ()));
79
+ "jvm_memory_bytes_committed" ,
80
+ Arrays . asList ( "area" ) ,
81
+ Arrays . asList ( "nonheap" ) ,
82
+ nonHeapUsage .getCommitted ()));
101
83
sampleFamilies .add (
102
84
new MetricFamilySamples (
103
- MEMORY_LIMIT_METRIC ,
85
+ "jvm_memory_bytes_committed" ,
104
86
Type .GAUGE ,
105
- "Limit (bytes) of a given JVM memory area (heap, nonheap)." ,
106
- limitSamples ));
87
+ "Committed (bytes) of a given JVM memory area." ,
88
+ committedSamples ));
89
+ ArrayList <MetricFamilySamples .Sample > maxSamples = new ArrayList <MetricFamilySamples .Sample >();
90
+ maxSamples .add (
91
+ new MetricFamilySamples .Sample (
92
+ "jvm_memory_bytes_max" ,
93
+ Arrays .asList ("area" ),
94
+ Arrays .asList ("heap" ),
95
+ heapUsage .getMax ()));
96
+ maxSamples .add (
97
+ new MetricFamilySamples .Sample (
98
+ "jvm_memory_bytes_max" ,
99
+ Arrays .asList ("area" ),
100
+ Arrays .asList ("nonheap" ),
101
+ nonHeapUsage .getMax ()));
102
+ sampleFamilies .add (
103
+ new MetricFamilySamples (
104
+ "jvm_memory_bytes_max" ,
105
+ Type .GAUGE ,
106
+ "Maximum (bytes) of a given JVM memory area." ,
107
+ maxSamples ));
107
108
}
108
109
109
110
void addMemoryPoolMetrics (List <MetricFamilySamples > sampleFamilies ) {
110
111
ArrayList <MetricFamilySamples .Sample > usedSamples = new ArrayList <MetricFamilySamples .Sample >();
111
- ArrayList <MetricFamilySamples .Sample > limitSamples = new ArrayList <MetricFamilySamples .Sample >();
112
+ ArrayList <MetricFamilySamples .Sample > committedSamples = new ArrayList <MetricFamilySamples .Sample >();
113
+ ArrayList <MetricFamilySamples .Sample > maxSamples = new ArrayList <MetricFamilySamples .Sample >();
112
114
for (final MemoryPoolMXBean pool : poolBeans ) {
113
115
MemoryUsage poolUsage = pool .getUsage ();
114
116
usedSamples .add (
115
117
new MetricFamilySamples .Sample (
116
- POOLS_USED_METRIC ,
117
- POOLS_LABEL_NAMES ,
118
- poolLabelValues . get (pool ),
118
+ "jvm_memory_pool_bytes_used" ,
119
+ Arrays . asList ( "pool" ) ,
120
+ Arrays . asList (pool . getName () ),
119
121
poolUsage .getUsed ()));
120
- limitSamples .add (
122
+ committedSamples .add (
121
123
new MetricFamilySamples .Sample (
122
- POOLS_LIMIT_METRIC ,
123
- POOLS_LABEL_NAMES ,
124
- poolLabelValues .get (pool ),
125
- poolUsage .getMax () != -1 ? poolUsage .getMax () : poolUsage .getCommitted ()));
124
+ "jvm_memory_pool_bytes_committed" ,
125
+ Arrays .asList ("pool" ),
126
+ Arrays .asList (pool .getName ()),
127
+ poolUsage .getCommitted ()));
128
+ maxSamples .add (
129
+ new MetricFamilySamples .Sample (
130
+ "jvm_memory_pool_bytes_max" ,
131
+ Arrays .asList ("pool" ),
132
+ Arrays .asList (pool .getName ()),
133
+ poolUsage .getMax ()));
126
134
}
127
135
sampleFamilies .add (
128
136
new MetricFamilySamples (
129
- POOLS_USED_METRIC ,
137
+ "jvm_memory_pool_bytes_used" ,
130
138
Type .GAUGE ,
131
139
"Used bytes of a given JVM memory pool." ,
132
140
usedSamples ));
133
141
134
142
sampleFamilies .add (
135
143
new MetricFamilySamples (
136
- POOLS_LIMIT_METRIC ,
144
+ "jvm_memory_pool_bytes_committed" ,
137
145
Type .GAUGE ,
138
146
"Limit (bytes) of a given JVM memory pool." ,
139
- limitSamples ));
147
+ committedSamples ));
148
+
149
+ sampleFamilies .add (
150
+ new MetricFamilySamples (
151
+ "jvm_memory_pool_bytes_max" ,
152
+ Type .GAUGE ,
153
+ "Max (bytes) of a given JVM memory pool." ,
154
+ maxSamples ));
140
155
}
141
156
142
157
0 commit comments