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  
36    public MetricsHBaseServer(String serverName, MetricsHBaseServerWrapper wrapper) {
37      source = CompatibilitySingletonFactory.getInstance(MetricsHBaseServerSourceFactory.class)
38                                            .create(serverName, wrapper);
39    }
40  
41    void authorizationSuccess() {
42      source.authorizationSuccess();
43    }
44  
45    void authorizationFailure() {
46      source.authorizationFailure();
47    }
48  
49    void authenticationFailure() {
50      source.authenticationFailure();
51    }
52  
53    void authenticationSuccess() {
54      source.authenticationSuccess();
55    }
56  
57    void sentBytes(long count) {
58      source.sentBytes(count);
59    }
60  
61    void receivedBytes(int count) {
62      source.receivedBytes(count);
63    }
64  
65    void dequeuedCall(int qTime) {
66      source.dequeuedCall(qTime);
67    }
68  
69    void processedCall(int processingTime) {
70      source.processedCall(processingTime);
71    }
72  
73    void totalCall(int totalTime) {
74      source.queuedAndProcessedCall(totalTime);
75    }
76  
77    public void exception(Throwable throwable) {
78      source.exception();
79  
80      /**
81       * Keep some metrics for commonly seen exceptions
82       *
83       * Try and  put the most common types first.
84       * Place child types before the parent type that they extend.
85       *
86       * If this gets much larger we might have to go to a hashmap
87       */
88      if (throwable != null) {
89        if (throwable instanceof OutOfOrderScannerNextException) {
90          source.outOfOrderException();
91        } else if (throwable instanceof RegionTooBusyException) {
92          source.tooBusyException();
93        } else if (throwable instanceof UnknownScannerException) {
94          source.unknownScannerException();
95        } else if (throwable instanceof ScannerResetException) {
96          source.scannerResetException();
97        } else if (throwable instanceof RegionMovedException) {
98          source.movedRegionException();
99        } else if (throwable instanceof NotServingRegionException) {
100         source.notServingRegionException();
101       } else if (throwable instanceof FailedSanityCheckException) {
102         source.failedSanityException();
103       }
104     }
105   }
106 
107   public MetricsHBaseServerSource getMetricsSource() {
108     return source;
109   }
110 }