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 public void exception(Throwable throwable) { 101 source.exception(); 102 103 /** 104 * Keep some metrics for commonly seen exceptions Try and put the most common types first. Place 105 * child types before the parent type that they extend. If this gets much larger we might have 106 * to go to a hashmap 107 */ 108 if (throwable != null) { 109 if (throwable instanceof OutOfOrderScannerNextException) { 110 source.outOfOrderException(); 111 } else if (throwable instanceof RegionTooBusyException) { 112 source.tooBusyException(); 113 } else if (throwable instanceof UnknownScannerException) { 114 source.unknownScannerException(); 115 } else if (throwable instanceof ScannerResetException) { 116 if (throwable.getCause() instanceof TimeoutIOException) { 117 // Thrown by RSRpcServices, this is more accurately reported as a timeout, 118 // since client will never see the actual reset exception 119 source.callTimedOut(); 120 } else { 121 source.scannerResetException(); 122 } 123 } else if (throwable instanceof RegionMovedException) { 124 source.movedRegionException(); 125 } else if (throwable instanceof NotServingRegionException) { 126 source.notServingRegionException(); 127 } else if (throwable instanceof FailedSanityCheckException) { 128 source.failedSanityException(); 129 } else if (throwable instanceof MultiActionResultTooLarge) { 130 source.multiActionTooLargeException(); 131 } else if (throwable instanceof CallQueueTooBigException) { 132 source.callQueueTooBigException(); 133 } else if (throwable instanceof QuotaExceededException) { 134 source.quotaExceededException(); 135 } else if (throwable instanceof RpcThrottlingException) { 136 source.rpcThrottlingException(); 137 } else if (throwable instanceof CallDroppedException) { 138 source.callDroppedException(); 139 } else if (throwable instanceof RequestTooBigException) { 140 source.requestTooBigException(); 141 } else { 142 source.otherExceptions(); 143 if (LOG.isDebugEnabled()) { 144 LOG.debug("Unknown exception type", throwable); 145 } 146 } 147 } 148 } 149 150 void callTimedOut() { 151 source.callTimedOut(); 152 } 153 154 public MetricsHBaseServerSource getMetricsSource() { 155 return source; 156 } 157 158 public MetricsHBaseServerWrapper getHBaseServerWrapper() { 159 return serverWrapper; 160 } 161}