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