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.hbase.metrics.Interns;
25 import org.apache.hadoop.metrics2.MetricsCollector;
26 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
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 private final MetricsHBaseServerWrapper wrapper;
35 private final MutableCounterLong authorizationSuccesses;
36 private final MutableCounterLong authorizationFailures;
37 private final MutableCounterLong authenticationSuccesses;
38 private final MutableCounterLong authenticationFailures;
39 private final MutableCounterLong sentBytes;
40 private final MutableCounterLong receivedBytes;
41
42 private final MutableCounterLong exceptions;
43 private final MutableCounterLong exceptionsOOO;
44 private final MutableCounterLong exceptionsBusy;
45 private final MutableCounterLong exceptionsUnknown;
46 private final MutableCounterLong exceptionsScannerReset;
47 private final MutableCounterLong exceptionsSanity;
48 private final MutableCounterLong exceptionsNSRE;
49 private final MutableCounterLong exceptionsMoved;
50
51
52 private MutableHistogram queueCallTime;
53 private MutableHistogram processCallTime;
54 private MutableHistogram totalCallTime;
55
56 public MetricsHBaseServerSourceImpl(String metricsName,
57 String metricsDescription,
58 String metricsContext,
59 String metricsJmxContext,
60 MetricsHBaseServerWrapper wrapper) {
61 super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
62 this.wrapper = wrapper;
63
64 this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
65 AUTHORIZATION_SUCCESSES_DESC, 0L);
66 this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
67 AUTHORIZATION_FAILURES_DESC, 0L);
68
69 this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
70 this.exceptionsOOO = this.getMetricsRegistry()
71 .newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
72 this.exceptionsBusy = this.getMetricsRegistry()
73 .newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
74 this.exceptionsUnknown = this.getMetricsRegistry()
75 .newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
76 this.exceptionsScannerReset = this.getMetricsRegistry()
77 .newCounter(EXCEPTIONS_SCANNER_RESET_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 }
100
101 @Override
102 public void authorizationSuccess() {
103 authorizationSuccesses.incr();
104 }
105
106 @Override
107 public void authorizationFailure() {
108 authorizationFailures.incr();
109 }
110
111 @Override
112 public void authenticationFailure() {
113 authenticationFailures.incr();
114 }
115
116 @Override
117 public void exception() {
118 exceptions.incr();
119 }
120
121 @Override
122 public void outOfOrderException() {
123 exceptionsOOO.incr();
124 }
125
126 @Override
127 public void failedSanityException() {
128 exceptionsSanity.incr();
129 }
130
131 @Override
132 public void movedRegionException() {
133 exceptionsMoved.incr();
134 }
135
136 @Override
137 public void notServingRegionException() {
138 exceptionsNSRE.incr();
139 }
140
141 @Override
142 public void unknownScannerException() {
143 exceptionsUnknown.incr();
144 }
145
146 @Override
147 public void scannerResetException() {
148 exceptionsScannerReset.incr();
149 }
150
151 @Override
152 public void tooBusyException() {
153 exceptionsBusy.incr();
154 }
155
156 @Override
157 public void authenticationSuccess() {
158 authenticationSuccesses.incr();
159 }
160
161 @Override
162 public void sentBytes(long count) {
163 this.sentBytes.incr(count);
164 }
165
166 @Override
167 public void receivedBytes(int count) {
168 this.receivedBytes.incr(count);
169 }
170
171 @Override
172 public void dequeuedCall(int qTime) {
173 queueCallTime.add(qTime);
174 }
175
176 @Override
177 public void processedCall(int processingTime) {
178 processCallTime.add(processingTime);
179 }
180
181 @Override
182 public void queuedAndProcessedCall(int totalTime) {
183 totalCallTime.add(totalTime);
184 }
185
186 @Override
187 public void getMetrics(MetricsCollector metricsCollector, boolean all) {
188 MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
189
190 if (wrapper != null) {
191 mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
192 .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
193 wrapper.getGeneralQueueLength())
194 .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
195 REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
196 .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
197 wrapper.getPriorityQueueLength())
198 .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
199 NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
200 .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
201 NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
202 }
203
204 metricsRegistry.snapshot(mrb, all);
205 }
206 }