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.NotServingRegionException;
23  import org.apache.hadoop.hbase.RegionTooBusyException;
24  import org.apache.hadoop.hbase.UnknownScannerException;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
27  import org.apache.hadoop.hbase.exceptions.FailedSanityCheckException;
28  import org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException;
29  import org.apache.hadoop.hbase.exceptions.RegionMovedException;
30  import org.apache.hadoop.hbase.exceptions.ScannerResetException;
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 sentBytes(long count) {
60      source.sentBytes(count);
61    }
62  
63    void receivedBytes(int count) {
64      source.receivedBytes(count);
65    }
66  
67    void sentResponse(long count) { source.sentResponse(count); }
68  
69    void receivedRequest(long count) { source.receivedRequest(count); }
70  
71    void dequeuedCall(int qTime) {
72      source.dequeuedCall(qTime);
73    }
74  
75    void processedCall(int processingTime) {
76      source.processedCall(processingTime);
77    }
78  
79    void totalCall(int totalTime) {
80      source.queuedAndProcessedCall(totalTime);
81    }
82  
83    public void exception(Throwable throwable) {
84      source.exception();
85  
86      /**
87       * Keep some metrics for commonly seen exceptions
88       *
89       * Try and  put the most common types first.
90       * Place child types before the parent type that they extend.
91       *
92       * If this gets much larger we might have to go to a hashmap
93       */
94      if (throwable != null) {
95        if (throwable instanceof OutOfOrderScannerNextException) {
96          source.outOfOrderException();
97        } else if (throwable instanceof RegionTooBusyException) {
98          source.tooBusyException();
99        } else if (throwable instanceof UnknownScannerException) {
100         source.unknownScannerException();
101       } else if (throwable instanceof ScannerResetException) {
102         source.scannerResetException();
103       } else if (throwable instanceof RegionMovedException) {
104         source.movedRegionException();
105       } else if (throwable instanceof NotServingRegionException) {
106         source.notServingRegionException();
107       } else if (throwable instanceof FailedSanityCheckException) {
108         source.failedSanityException();
109       }
110     }
111   }
112 
113   public MetricsHBaseServerSource getMetricsSource() {
114     return source;
115   }
116 
117   public MetricsHBaseServerWrapper getHBaseServerWrapper() {
118     return serverWrapper;
119   }
120 }