001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.ipc;
019
020import org.apache.hadoop.hbase.CallDroppedException;
021import org.apache.hadoop.hbase.CallQueueTooBigException;
022import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
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.hadoop.hbase.exceptions.FailedSanityCheckException;
028import org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException;
029import org.apache.hadoop.hbase.exceptions.RegionMovedException;
030import org.apache.hadoop.hbase.exceptions.RequestTooBigException;
031import org.apache.hadoop.hbase.exceptions.ScannerResetException;
032import org.apache.hadoop.hbase.exceptions.TimeoutIOException;
033import org.apache.hadoop.hbase.quotas.QuotaExceededException;
034import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
035import org.apache.yetus.audience.InterfaceAudience;
036import org.slf4j.Logger;
037import org.slf4j.LoggerFactory;
038
039@InterfaceAudience.Private
040public class MetricsHBaseServer {
041  private static final Logger LOG = LoggerFactory.getLogger(MetricsHBaseServer.class);
042
043  private MetricsHBaseServerSource source;
044  private MetricsHBaseServerWrapper serverWrapper;
045
046  public MetricsHBaseServer(String serverName, MetricsHBaseServerWrapper wrapper) {
047    serverWrapper = wrapper;
048    source = CompatibilitySingletonFactory.getInstance(MetricsHBaseServerSourceFactory.class)
049      .create(serverName, wrapper);
050  }
051
052  void authorizationSuccess() {
053    source.authorizationSuccess();
054  }
055
056  void authorizationFailure() {
057    source.authorizationFailure();
058  }
059
060  void authenticationFailure() {
061    source.authenticationFailure();
062  }
063
064  void authenticationSuccess() {
065    source.authenticationSuccess();
066  }
067
068  void authenticationFallback() {
069    source.authenticationFallback();
070  }
071
072  void sentBytes(long count) {
073    source.sentBytes(count);
074  }
075
076  void receivedBytes(int count) {
077    source.receivedBytes(count);
078  }
079
080  void sentResponse(long count) {
081    source.sentResponse(count);
082  }
083
084  void receivedRequest(long count) {
085    source.receivedRequest(count);
086  }
087
088  void dequeuedCall(int qTime) {
089    source.dequeuedCall(qTime);
090  }
091
092  void processedCall(int processingTime) {
093    source.processedCall(processingTime);
094  }
095
096  void totalCall(int totalTime) {
097    source.queuedAndProcessedCall(totalTime);
098  }
099
100  void unwritableTime(long unwritableTime) {
101    source.unwritableTime(unwritableTime);
102  }
103
104  void maxOutboundBytesExceeded() {
105    source.maxOutboundBytesExceeded();
106  }
107
108  public void exception(Throwable throwable) {
109    source.exception();
110
111    /**
112     * Keep some metrics for commonly seen exceptions Try and put the most common types first. Place
113     * child types before the parent type that they extend. If this gets much larger we might have
114     * to go to a hashmap
115     */
116    if (throwable != null) {
117      if (throwable instanceof OutOfOrderScannerNextException) {
118        source.outOfOrderException();
119      } else if (throwable instanceof RegionTooBusyException) {
120        source.tooBusyException();
121      } else if (throwable instanceof UnknownScannerException) {
122        source.unknownScannerException();
123      } else if (throwable instanceof ScannerResetException) {
124        if (throwable.getCause() instanceof TimeoutIOException) {
125          // Thrown by RSRpcServices, this is more accurately reported as a timeout,
126          // since client will never see the actual reset exception
127          source.callTimedOut();
128        } else {
129          source.scannerResetException();
130        }
131      } else if (throwable instanceof RegionMovedException) {
132        source.movedRegionException();
133      } else if (throwable instanceof NotServingRegionException) {
134        source.notServingRegionException();
135      } else if (throwable instanceof FailedSanityCheckException) {
136        source.failedSanityException();
137      } else if (throwable instanceof MultiActionResultTooLarge) {
138        source.multiActionTooLargeException();
139      } else if (throwable instanceof CallQueueTooBigException) {
140        source.callQueueTooBigException();
141      } else if (throwable instanceof QuotaExceededException) {
142        source.quotaExceededException();
143      } else if (throwable instanceof RpcThrottlingException) {
144        source.rpcThrottlingException();
145      } else if (throwable instanceof CallDroppedException) {
146        source.callDroppedException();
147      } else if (throwable instanceof RequestTooBigException) {
148        source.requestTooBigException();
149      } else {
150        source.otherExceptions();
151        if (LOG.isDebugEnabled()) {
152          LOG.debug("Unknown exception type", throwable);
153        }
154      }
155    }
156  }
157
158  void callTimedOut() {
159    source.callTimedOut();
160  }
161
162  public MetricsHBaseServerSource getMetricsSource() {
163    return source;
164  }
165
166  public MetricsHBaseServerWrapper getHBaseServerWrapper() {
167    return serverWrapper;
168  }
169}