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