001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.ipc;
021
022import org.apache.hadoop.hbase.CallQueueTooBigException;
023import org.apache.hadoop.hbase.MultiActionResultTooLarge;
024import org.apache.hadoop.hbase.NotServingRegionException;
025import org.apache.hadoop.hbase.RegionTooBusyException;
026import org.apache.hadoop.hbase.UnknownScannerException;
027import org.apache.yetus.audience.InterfaceAudience;
028import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
029import org.apache.hadoop.hbase.exceptions.FailedSanityCheckException;
030import org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException;
031import org.apache.hadoop.hbase.exceptions.RegionMovedException;
032import org.apache.hadoop.hbase.exceptions.ScannerResetException;
033
034@InterfaceAudience.Private
035public class MetricsHBaseServer {
036  private MetricsHBaseServerSource source;
037  private MetricsHBaseServerWrapper serverWrapper;
038
039  public MetricsHBaseServer(String serverName, MetricsHBaseServerWrapper wrapper) {
040    serverWrapper = wrapper;
041    source = CompatibilitySingletonFactory.getInstance(MetricsHBaseServerSourceFactory.class)
042                                          .create(serverName, wrapper);
043  }
044
045  void authorizationSuccess() {
046    source.authorizationSuccess();
047  }
048
049  void authorizationFailure() {
050    source.authorizationFailure();
051  }
052
053  void authenticationFailure() {
054    source.authenticationFailure();
055  }
056
057  void authenticationSuccess() {
058    source.authenticationSuccess();
059  }
060
061  void authenticationFallback() {
062    source.authenticationFallback();
063  }
064
065  void sentBytes(long count) {
066    source.sentBytes(count);
067  }
068
069  void receivedBytes(int count) {
070    source.receivedBytes(count);
071  }
072
073  void sentResponse(long count) { source.sentResponse(count); }
074
075  void receivedRequest(long count) { source.receivedRequest(count); }
076
077  void dequeuedCall(int qTime) {
078    source.dequeuedCall(qTime);
079  }
080
081  void processedCall(int processingTime) {
082    source.processedCall(processingTime);
083  }
084
085  void totalCall(int totalTime) {
086    source.queuedAndProcessedCall(totalTime);
087  }
088
089  public void exception(Throwable throwable) {
090    source.exception();
091
092    /**
093     * Keep some metrics for commonly seen exceptions
094     *
095     * Try and  put the most common types first.
096     * Place child types before the parent type that they extend.
097     *
098     * If this gets much larger we might have to go to a hashmap
099     */
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}