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