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