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