1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.ipc;
21
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
24 import org.apache.hadoop.metrics2.MetricsCollector;
25 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
26 import org.apache.hadoop.metrics2.lib.Interns;
27 import org.apache.hadoop.metrics2.lib.MutableCounterLong;
28 import org.apache.hadoop.metrics2.lib.MutableHistogram;
29
30 @InterfaceAudience.Private
31 public class MetricsHBaseServerSourceImpl extends BaseSourceImpl
32 implements MetricsHBaseServerSource {
33
34
35 private final MetricsHBaseServerWrapper wrapper;
36 private final MutableCounterLong authorizationSuccesses;
37 private final MutableCounterLong authorizationFailures;
38 private final MutableCounterLong authenticationSuccesses;
39 private final MutableCounterLong authenticationFailures;
40 private final MutableCounterLong authenticationFallbacks;
41 private final MutableCounterLong sentBytes;
42 private final MutableCounterLong receivedBytes;
43
44 private final MutableCounterLong exceptions;
45 private final MutableCounterLong exceptionsOOO;
46 private final MutableCounterLong exceptionsBusy;
47 private final MutableCounterLong exceptionsUnknown;
48 private final MutableCounterLong exceptionsSanity;
49 private final MutableCounterLong exceptionsNSRE;
50 private final MutableCounterLong exceptionsMoved;
51 private final MutableCounterLong exceptionsMultiTooLarge;
52
53
54 private MutableHistogram queueCallTime;
55 private MutableHistogram processCallTime;
56 private MutableHistogram totalCallTime;
57 private MutableHistogram requestSize;
58 private MutableHistogram responseSize;
59
60 public MetricsHBaseServerSourceImpl(String metricsName,
61 String metricsDescription,
62 String metricsContext,
63 String metricsJmxContext,
64 MetricsHBaseServerWrapper wrapper) {
65 super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
66 this.wrapper = wrapper;
67
68 this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
69 AUTHORIZATION_SUCCESSES_DESC, 0L);
70 this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
71 AUTHORIZATION_FAILURES_DESC, 0L);
72
73 this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
74 this.exceptionsOOO = this.getMetricsRegistry()
75 .newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
76 this.exceptionsBusy = this.getMetricsRegistry()
77 .newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
78 this.exceptionsUnknown = this.getMetricsRegistry()
79 .newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
80 this.exceptionsSanity = this.getMetricsRegistry()
81 .newCounter(EXCEPTIONS_SANITY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
82 this.exceptionsMoved = this.getMetricsRegistry()
83 .newCounter(EXCEPTIONS_MOVED_NAME, EXCEPTIONS_TYPE_DESC, 0L);
84 this.exceptionsNSRE = this.getMetricsRegistry()
85 .newCounter(EXCEPTIONS_NSRE_NAME, EXCEPTIONS_TYPE_DESC, 0L);
86 this.exceptionsMultiTooLarge = this.getMetricsRegistry()
87 .newCounter(EXCEPTIONS_MULTI_TOO_LARGE_NAME, EXCEPTIONS_MULTI_TOO_LARGE_DESC, 0L);
88
89 this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
90 AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0L);
91 this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
92 AUTHENTICATION_FAILURES_DESC, 0L);
93 this.authenticationFallbacks = this.getMetricsRegistry().newCounter(
94 AUTHENTICATION_FALLBACKS_NAME, AUTHENTICATION_FALLBACKS_DESC, 0L);
95 this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
96 SENT_BYTES_DESC, 0L);
97 this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
98 RECEIVED_BYTES_DESC, 0L);
99 this.queueCallTime = this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME,
100 QUEUE_CALL_TIME_DESC);
101 this.processCallTime = this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME,
102 PROCESS_CALL_TIME_DESC);
103 this.totalCallTime = this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME,
104 TOTAL_CALL_TIME_DESC);
105 this.requestSize = this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME,
106 REQUEST_SIZE_DESC);
107 this.responseSize = this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME,
108 RESPONSE_SIZE_DESC);
109 }
110
111 @Override
112 public void authorizationSuccess() {
113 authorizationSuccesses.incr();
114 }
115
116 @Override
117 public void authorizationFailure() {
118 authorizationFailures.incr();
119 }
120
121 @Override
122 public void authenticationFailure() {
123 authenticationFailures.incr();
124 }
125
126 @Override
127 public void authenticationFallback() {
128 authenticationFallbacks.incr();
129 }
130
131 @Override
132 public void exception() {
133 exceptions.incr();
134 }
135
136 @Override
137 public void outOfOrderException() {
138 exceptionsOOO.incr();
139 }
140
141 @Override
142 public void failedSanityException() {
143 exceptionsSanity.incr();
144 }
145
146 @Override
147 public void movedRegionException() {
148 exceptionsMoved.incr();
149 }
150
151 @Override
152 public void notServingRegionException() {
153 exceptionsNSRE.incr();
154 }
155
156 @Override
157 public void unknownScannerException() {
158 exceptionsUnknown.incr();
159 }
160
161 @Override
162 public void tooBusyException() {
163 exceptionsBusy.incr();
164 }
165
166 @Override
167 public void multiActionTooLargeException() {
168 exceptionsMultiTooLarge.incr();
169 }
170
171 @Override
172 public void authenticationSuccess() {
173 authenticationSuccesses.incr();
174 }
175
176 @Override
177 public void sentBytes(long count) {
178 this.sentBytes.incr(count);
179 }
180
181 @Override
182 public void receivedBytes(int count) {
183 this.receivedBytes.incr(count);
184 }
185
186 @Override
187 public void sentResponse(long count) { this.responseSize.add(count); }
188
189 @Override
190 public void receivedRequest(long count) { this.requestSize.add(count); }
191
192 @Override
193 public void dequeuedCall(int qTime) {
194 queueCallTime.add(qTime);
195 }
196
197 @Override
198 public void processedCall(int processingTime) {
199 processCallTime.add(processingTime);
200 }
201
202 @Override
203 public void queuedAndProcessedCall(int totalTime) {
204 totalCallTime.add(totalTime);
205 }
206
207 @Override
208 public void getMetrics(MetricsCollector metricsCollector, boolean all) {
209 MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
210
211 if (wrapper != null) {
212 mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
213 .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
214 wrapper.getGeneralQueueLength())
215 .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
216 REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
217 .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
218 wrapper.getPriorityQueueLength())
219 .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
220 NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
221 .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
222 NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
223 }
224
225 metricsRegistry.snapshot(mrb, all);
226 }
227 }