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