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