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