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