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