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