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.MultiActionResultTooLarge;
23  import org.apache.hadoop.hbase.NotServingRegionException;
24  import org.apache.hadoop.hbase.RegionTooBusyException;
25  import org.apache.hadoop.hbase.UnknownScannerException;
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
28  import org.apache.hadoop.hbase.exceptions.FailedSanityCheckException;
29  import org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException;
30  import org.apache.hadoop.hbase.exceptions.RegionMovedException;
31  
32  @InterfaceAudience.Private
33  public class MetricsHBaseServer {
34    private MetricsHBaseServerSource source;
35    private MetricsHBaseServerWrapper serverWrapper;
36  
37    public MetricsHBaseServer(String serverName, MetricsHBaseServerWrapper wrapper) {
38      serverWrapper = wrapper;
39      source = CompatibilitySingletonFactory.getInstance(MetricsHBaseServerSourceFactory.class)
40                                            .create(serverName, wrapper);
41    }
42  
43    void authorizationSuccess() {
44      source.authorizationSuccess();
45    }
46  
47    void authorizationFailure() {
48      source.authorizationFailure();
49    }
50  
51    void authenticationFailure() {
52      source.authenticationFailure();
53    }
54  
55    void authenticationSuccess() {
56      source.authenticationSuccess();
57    }
58  
59    void authenticationFallback() {
60      source.authenticationFallback();
61    }
62  
63    void sentBytes(long count) {
64      source.sentBytes(count);
65    }
66  
67    void receivedBytes(int count) {
68      source.receivedBytes(count);
69    }
70  
71    void sentResponse(long count) { source.sentResponse(count); }
72  
73    void receivedRequest(long count) { source.receivedRequest(count); }
74  
75    void dequeuedCall(int qTime) {
76      source.dequeuedCall(qTime);
77    }
78  
79    void processedCall(int processingTime) {
80      source.processedCall(processingTime);
81    }
82  
83    void totalCall(int totalTime) {
84      source.queuedAndProcessedCall(totalTime);
85    }
86  
87    public void exception(Throwable throwable) {
88      source.exception();
89  
90      /**
91       * Keep some metrics for commonly seen exceptions
92       *
93       * Try and  put the most common types first.
94       * Place child types before the parent type that they extend.
95       *
96       * If this gets much larger we might have to go to a hashmap
97       */
98      if (throwable != null) {
99        if (throwable instanceof OutOfOrderScannerNextException) {
100         source.outOfOrderException();
101       } else if (throwable instanceof RegionTooBusyException) {
102         source.tooBusyException();
103       } else if (throwable instanceof UnknownScannerException) {
104         source.unknownScannerException();
105       } else if (throwable instanceof RegionMovedException) {
106         source.movedRegionException();
107       } else if (throwable instanceof NotServingRegionException) {
108         source.notServingRegionException();
109       } else if (throwable instanceof FailedSanityCheckException) {
110         source.failedSanityException();
111       } else if (throwable instanceof MultiActionResultTooLarge) {
112         source.multiActionTooLargeException();
113       }
114     }
115   }
116 
117   public MetricsHBaseServerSource getMetricsSource() {
118     return source;
119   }
120 
121   public MetricsHBaseServerWrapper getHBaseServerWrapper() {
122     return serverWrapper;
123   }
124 }