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