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