View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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  
35    private final MetricsHBaseServerWrapper wrapper;
36    private final MutableFastCounter authorizationSuccesses;
37    private final MutableFastCounter authorizationFailures;
38    private final MutableFastCounter authenticationSuccesses;
39    private final MutableFastCounter authenticationFailures;
40    private final MutableFastCounter authenticationFallbacks;
41    private final MutableFastCounter sentBytes;
42    private final MutableFastCounter receivedBytes;
43  
44    private final MutableFastCounter exceptions;
45    private final MutableFastCounter exceptionsOOO;
46    private final MutableFastCounter exceptionsBusy;
47    private final MutableFastCounter exceptionsUnknown;
48    private final MutableFastCounter exceptionsSanity;
49    private final MutableFastCounter exceptionsNSRE;
50    private final MutableFastCounter exceptionsMoved;
51    private final MutableFastCounter exceptionsMultiTooLarge;
52  
53  
54    private MetricHistogram queueCallTime;
55    private MetricHistogram processCallTime;
56    private MetricHistogram totalCallTime;
57    private MetricHistogram requestSize;
58    private MetricHistogram responseSize;
59  
60    public MetricsHBaseServerSourceImpl(String metricsName,
61                                        String metricsDescription,
62                                        String metricsContext,
63                                        String metricsJmxContext,
64                                        MetricsHBaseServerWrapper wrapper) {
65      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
66      this.wrapper = wrapper;
67  
68      this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
69          AUTHORIZATION_SUCCESSES_DESC, 0L);
70      this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
71          AUTHORIZATION_FAILURES_DESC, 0L);
72  
73      this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
74      this.exceptionsOOO = this.getMetricsRegistry()
75          .newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
76      this.exceptionsBusy = this.getMetricsRegistry()
77          .newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
78      this.exceptionsUnknown = this.getMetricsRegistry()
79          .newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
80      this.exceptionsSanity = this.getMetricsRegistry()
81          .newCounter(EXCEPTIONS_SANITY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
82      this.exceptionsMoved = this.getMetricsRegistry()
83          .newCounter(EXCEPTIONS_MOVED_NAME, EXCEPTIONS_TYPE_DESC, 0L);
84      this.exceptionsNSRE = this.getMetricsRegistry()
85          .newCounter(EXCEPTIONS_NSRE_NAME, EXCEPTIONS_TYPE_DESC, 0L);
86      this.exceptionsMultiTooLarge = this.getMetricsRegistry()
87          .newCounter(EXCEPTIONS_MULTI_TOO_LARGE_NAME, EXCEPTIONS_MULTI_TOO_LARGE_DESC, 0L);
88  
89      this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
90          AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0L);
91      this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
92          AUTHENTICATION_FAILURES_DESC, 0L);
93      this.authenticationFallbacks = this.getMetricsRegistry().newCounter(
94          AUTHENTICATION_FALLBACKS_NAME, AUTHENTICATION_FALLBACKS_DESC, 0L);
95      this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
96          SENT_BYTES_DESC, 0L);
97      this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
98          RECEIVED_BYTES_DESC, 0L);
99      this.queueCallTime = this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME,
100         QUEUE_CALL_TIME_DESC);
101     this.processCallTime = this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME,
102         PROCESS_CALL_TIME_DESC);
103     this.totalCallTime = this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME,
104         TOTAL_CALL_TIME_DESC);
105     this.requestSize = this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME,
106         REQUEST_SIZE_DESC);
107     this.responseSize = this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME,
108               RESPONSE_SIZE_DESC);
109   }
110 
111   @Override
112   public void authorizationSuccess() {
113     authorizationSuccesses.incr();
114   }
115 
116   @Override
117   public void authorizationFailure() {
118     authorizationFailures.incr();
119   }
120 
121   @Override
122   public void authenticationFailure() {
123     authenticationFailures.incr();
124   }
125 
126   @Override
127   public void authenticationFallback() {
128     authenticationFallbacks.incr();
129   }
130 
131   @Override
132   public void exception() {
133     exceptions.incr();
134   }
135 
136   @Override
137   public void outOfOrderException() {
138     exceptionsOOO.incr();
139   }
140 
141   @Override
142   public void failedSanityException() {
143     exceptionsSanity.incr();
144   }
145 
146   @Override
147   public void movedRegionException() {
148     exceptionsMoved.incr();
149   }
150 
151   @Override
152   public void notServingRegionException() {
153     exceptionsNSRE.incr();
154   }
155 
156   @Override
157   public void unknownScannerException() {
158     exceptionsUnknown.incr();
159   }
160 
161   @Override
162   public void tooBusyException() {
163     exceptionsBusy.incr();
164   }
165 
166   @Override
167   public void multiActionTooLargeException() {
168     exceptionsMultiTooLarge.incr();
169   }
170 
171   @Override
172   public void authenticationSuccess() {
173     authenticationSuccesses.incr();
174   }
175 
176   @Override
177   public void sentBytes(long count) {
178     this.sentBytes.incr(count);
179   }
180 
181   @Override
182   public void receivedBytes(int count) {
183     this.receivedBytes.incr(count);
184   }
185 
186   @Override
187   public void sentResponse(long count) { this.responseSize.add(count); }
188 
189   @Override
190   public void receivedRequest(long count) { this.requestSize.add(count); }
191 
192   @Override
193   public void dequeuedCall(int qTime) {
194     queueCallTime.add(qTime);
195   }
196 
197   @Override
198   public void processedCall(int processingTime) {
199     processCallTime.add(processingTime);
200   }
201 
202   @Override
203   public void queuedAndProcessedCall(int totalTime) {
204     totalCallTime.add(totalTime);
205   }
206 
207   @Override
208   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
209     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
210 
211     if (wrapper != null) {
212       mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
213           .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
214               wrapper.getGeneralQueueLength())
215           .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
216               REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
217           .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
218               wrapper.getPriorityQueueLength())
219           .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
220               NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
221           .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
222               NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount())
223           .addCounter(Interns.info(NUM_GENERAL_CALLS_DROPPED_NAME,
224               NUM_GENERAL_CALLS_DROPPED_DESC), wrapper.getNumGeneralCallsDropped())
225           .addCounter(Interns.info(NUM_LIFO_MODE_SWITCHES_NAME,
226               NUM_LIFO_MODE_SWITCHES_DESC), wrapper.getNumLifoModeSwitches());
227     }
228 
229     metricsRegistry.snapshot(mrb, all);
230   }
231 }