Skip to content

Commit c15ac30

Browse files
authored
Support collect ZGC memory pool metrics (#622)
1 parent 017bc20 commit c15ac30

4 files changed

Lines changed: 76 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Release Notes.
1515
* Support report MongoDB instance info in Mongodb 4.x plugin.
1616
* To compatible upper and lower case Oracle TNS url parse.
1717
* Fix config length limitation.
18+
* Support collecting ZGC memory pool metrics. Require OAP 9.7.0 to support these new metrics.
19+
1820

1921
#### Documentation
2022

apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/memorypool/MemoryPoolProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ private MemoryPoolMetricsAccessor findByBeanName(String name) {
6161
} else if (name.equals("Survivor Space")) {
6262
// Serial collector ( -XX:+UseSerialGC )
6363
return new SerialCollectorModule(beans);
64+
} else if (name.equals("ZHeap")) {
65+
// ZGC collector ( -XX:+UseZGC )
66+
return new ZGCCollectorModule(beans);
6467
} else {
6568
// Unknown
6669
return null;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.agent.core.jvm.memorypool;
20+
21+
import org.apache.skywalking.apm.network.language.agent.v3.MemoryPool;
22+
import org.apache.skywalking.apm.network.language.agent.v3.PoolType;
23+
24+
import java.lang.management.MemoryPoolMXBean;
25+
import java.lang.management.MemoryUsage;
26+
import java.util.LinkedList;
27+
import java.util.List;
28+
29+
public class ZGCCollectorModule implements MemoryPoolMetricsAccessor {
30+
31+
private final List<MemoryPoolMXBean> beans;
32+
33+
public ZGCCollectorModule(List<MemoryPoolMXBean> beans) {
34+
this.beans = beans;
35+
}
36+
37+
@Override
38+
public List<MemoryPool> getMemoryPoolMetricsList() {
39+
List<MemoryPool> poolList = new LinkedList<>();
40+
for (MemoryPoolMXBean bean : beans) {
41+
String name = bean.getName();
42+
PoolType type;
43+
if (name.equals("ZHeap")) {
44+
type = PoolType.ZHEAP_USAGE;
45+
} else if (name.equals("Metaspace")) {
46+
type = PoolType.METASPACE_USAGE;
47+
} else if (name.equals("Compressed Class Space")) {
48+
type = PoolType.COMPRESSED_CLASS_SPACE_USAGE;
49+
} else if (name.equals("CodeHeap 'non-nmethods'")) {
50+
type = PoolType.CODEHEAP_NON_NMETHODS_USAGE;
51+
} else if (name.equals("CodeHeap 'profiled nmethods'")) {
52+
type = PoolType.CODEHEAP_PROFILED_NMETHODS_USAGE;
53+
} else if (name.equals("CodeHeap 'non-profiled nmethods'")) {
54+
type = PoolType.CODEHEAP_NON_PROFILED_NMETHODS_USAGE;
55+
} else {
56+
continue;
57+
}
58+
59+
MemoryUsage usage = bean.getUsage();
60+
poolList.add(MemoryPool.newBuilder()
61+
.setType(type)
62+
.setInit(usage.getInit())
63+
.setMax(usage.getMax())
64+
.setCommitted(usage.getCommitted())
65+
.setUsed(usage.getUsed())
66+
.build());
67+
}
68+
return poolList;
69+
}
70+
}

0 commit comments

Comments
 (0)