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