/root/doris/be/src/util/jvm_metrics.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with 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, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include "jni.h" |
21 | | #include "util/jni-util.h" |
22 | | #include "util/metrics.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class JvmMetrics; |
27 | | |
28 | | class JvmStats { |
29 | | private: |
30 | | Jni::GlobalClass _managementFactoryClass; |
31 | | Jni::MethodId _getMemoryMXBeanMethod; |
32 | | Jni::GlobalClass _memoryUsageClass; |
33 | | Jni::GlobalClass _memoryMXBeanClass; |
34 | | Jni::MethodId _getHeapMemoryUsageMethod; |
35 | | Jni::MethodId _getNonHeapMemoryUsageMethod; |
36 | | Jni::MethodId _getMemoryUsageUsedMethod; |
37 | | Jni::MethodId _getMemoryUsageCommittedMethod; |
38 | | Jni::MethodId _getMemoryUsageMaxMethod; |
39 | | |
40 | | Jni::MethodId _getMemoryPoolMXBeansMethod; |
41 | | |
42 | | Jni::GlobalClass _listClass; |
43 | | Jni::MethodId _getListSizeMethod; |
44 | | Jni::MethodId _getListUseIndexMethod; |
45 | | |
46 | | Jni::GlobalClass _memoryPoolMXBeanClass; |
47 | | Jni::MethodId _getMemoryPoolMXBeanUsageMethod; |
48 | | Jni::MethodId _getMemoryPoolMXBeanPeakMethod; |
49 | | Jni::MethodId _getMemoryPoolMXBeanNameMethod; |
50 | | |
51 | | enum memoryPoolNameEnum { YOUNG, SURVIVOR, OLD }; |
52 | | const std::map<std::string, memoryPoolNameEnum> _memoryPoolName = { |
53 | | {"Eden Space", YOUNG}, |
54 | | {"PS Eden Space", YOUNG}, |
55 | | {"Par Eden Space", YOUNG}, |
56 | | {"G1 Eden Space", YOUNG}, |
57 | | |
58 | | {"Survivor Space", SURVIVOR}, |
59 | | {"PS Survivor Space", SURVIVOR}, |
60 | | {"Par Survivor Space", SURVIVOR}, |
61 | | {"G1 Survivor Space", SURVIVOR}, |
62 | | |
63 | | {"Tenured Gen", OLD}, |
64 | | {"PS Old Gen", OLD}, |
65 | | {"CMS Old Gen", OLD}, |
66 | | {"G1 Old Gen", OLD}, |
67 | | |
68 | | }; |
69 | | |
70 | | Jni::MethodId _getThreadMXBeanMethod; |
71 | | Jni::GlobalClass _threadMXBeanClass; |
72 | | Jni::MethodId _getAllThreadIdsMethod; |
73 | | Jni::MethodId _getThreadInfoMethod; |
74 | | Jni::GlobalClass _threadInfoClass; |
75 | | |
76 | | Jni::MethodId _getPeakThreadCountMethod; |
77 | | |
78 | | Jni::MethodId _getThreadStateMethod; |
79 | | Jni::GlobalClass _threadStateClass; |
80 | | |
81 | | Jni::GlobalObject _newThreadStateObj; |
82 | | Jni::GlobalObject _runnableThreadStateObj; |
83 | | Jni::GlobalObject _blockedThreadStateObj; |
84 | | Jni::GlobalObject _waitingThreadStateObj; |
85 | | Jni::GlobalObject _timedWaitingThreadStateObj; |
86 | | Jni::GlobalObject _terminatedThreadStateObj; |
87 | | |
88 | | Jni::GlobalClass _garbageCollectorMXBeanClass; |
89 | | Jni::MethodId _getGCNameMethod; |
90 | | Jni::MethodId _getGarbageCollectorMXBeansMethod; |
91 | | Jni::MethodId _getGCCollectionCountMethod; |
92 | | Jni::MethodId _getGCCollectionTimeMethod; |
93 | | |
94 | | bool _init_complete = false; |
95 | | |
96 | | public: |
97 | | Status init(); |
98 | 0 | bool init_complete() const { return _init_complete; } |
99 | 0 | void set_complete(bool val) { _init_complete = val; } |
100 | | Status refresh(JvmMetrics* jvm_metrics) const; |
101 | | ~JvmStats(); |
102 | | }; |
103 | | |
104 | | class JvmMetrics { |
105 | | public: |
106 | | JvmMetrics(MetricRegistry* registry); |
107 | | ~JvmMetrics(); |
108 | | void update(); |
109 | | |
110 | | IntGauge* jvm_heap_size_bytes_max = nullptr; |
111 | | IntGauge* jvm_heap_size_bytes_committed = nullptr; |
112 | | IntGauge* jvm_heap_size_bytes_used = nullptr; |
113 | | |
114 | | IntGauge* jvm_non_heap_size_bytes_used = nullptr; |
115 | | IntGauge* jvm_non_heap_size_bytes_committed = nullptr; |
116 | | |
117 | | IntGauge* jvm_young_size_bytes_used = nullptr; |
118 | | IntGauge* jvm_young_size_bytes_peak_used = nullptr; |
119 | | IntGauge* jvm_young_size_bytes_max = nullptr; |
120 | | |
121 | | IntGauge* jvm_old_size_bytes_used = nullptr; |
122 | | IntGauge* jvm_old_size_bytes_peak_used = nullptr; |
123 | | IntGauge* jvm_old_size_bytes_max = nullptr; |
124 | | |
125 | | IntGauge* jvm_thread_count = nullptr; |
126 | | IntGauge* jvm_thread_peak_count = nullptr; |
127 | | IntGauge* jvm_thread_new_count = nullptr; |
128 | | IntGauge* jvm_thread_runnable_count = nullptr; |
129 | | IntGauge* jvm_thread_blocked_count = nullptr; |
130 | | IntGauge* jvm_thread_waiting_count = nullptr; |
131 | | IntGauge* jvm_thread_timed_waiting_count = nullptr; |
132 | | IntGauge* jvm_thread_terminated_count = nullptr; |
133 | | |
134 | | IntGauge* jvm_gc_g1_young_generation_count = nullptr; |
135 | | IntGauge* jvm_gc_g1_young_generation_time_ms = nullptr; |
136 | | IntGauge* jvm_gc_g1_old_generation_count = nullptr; |
137 | | IntGauge* jvm_gc_g1_old_generation_time_ms = nullptr; |
138 | | |
139 | | private: |
140 | | JvmStats _jvm_stats; |
141 | | std::shared_ptr<MetricEntity> _server_entity; |
142 | | static const char* _s_hook_name; |
143 | | MetricRegistry* _registry = nullptr; |
144 | | }; |
145 | | |
146 | | } // namespace doris |