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.metrics.ExceptionTrackingSourceImpl; 021import org.apache.hadoop.hbase.metrics.Interns; 022import org.apache.hadoop.metrics2.MetricHistogram; 023import org.apache.hadoop.metrics2.MetricsCollector; 024import org.apache.hadoop.metrics2.MetricsRecordBuilder; 025import org.apache.hadoop.metrics2.lib.MutableFastCounter; 026import org.apache.yetus.audience.InterfaceAudience; 027 028@InterfaceAudience.Private 029public class MetricsHBaseServerSourceImpl extends ExceptionTrackingSourceImpl 030 implements MetricsHBaseServerSource { 031 private final MetricsHBaseServerWrapper wrapper; 032 private final MutableFastCounter authorizationSuccesses; 033 private final MutableFastCounter authorizationFailures; 034 private final MutableFastCounter authenticationSuccesses; 035 private final MutableFastCounter authenticationFailures; 036 private final MutableFastCounter authenticationFallbacks; 037 private final MutableFastCounter sentBytes; 038 private final MutableFastCounter receivedBytes; 039 040 private MetricHistogram queueCallTime; 041 private MetricHistogram processCallTime; 042 private MetricHistogram totalCallTime; 043 private MetricHistogram requestSize; 044 private MetricHistogram responseSize; 045 046 public MetricsHBaseServerSourceImpl(String metricsName, String metricsDescription, 047 String metricsContext, String metricsJmxContext, MetricsHBaseServerWrapper wrapper) { 048 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 049 this.wrapper = wrapper; 050 051 this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME, 052 AUTHORIZATION_SUCCESSES_DESC, 0L); 053 this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME, 054 AUTHORIZATION_FAILURES_DESC, 0L); 055 this.authenticationSuccesses = this.getMetricsRegistry() 056 .newCounter(AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0L); 057 this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME, 058 AUTHENTICATION_FAILURES_DESC, 0L); 059 this.authenticationFallbacks = this.getMetricsRegistry() 060 .newCounter(AUTHENTICATION_FALLBACKS_NAME, AUTHENTICATION_FALLBACKS_DESC, 0L); 061 this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME, SENT_BYTES_DESC, 0L); 062 this.receivedBytes = 063 this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME, RECEIVED_BYTES_DESC, 0L); 064 this.queueCallTime = 065 this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME, QUEUE_CALL_TIME_DESC); 066 this.processCallTime = 067 this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME, PROCESS_CALL_TIME_DESC); 068 this.totalCallTime = 069 this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME, TOTAL_CALL_TIME_DESC); 070 this.requestSize = 071 this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME, REQUEST_SIZE_DESC); 072 this.responseSize = 073 this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME, RESPONSE_SIZE_DESC); 074 } 075 076 @Override 077 public void authorizationSuccess() { 078 authorizationSuccesses.incr(); 079 } 080 081 @Override 082 public void authorizationFailure() { 083 authorizationFailures.incr(); 084 } 085 086 @Override 087 public void authenticationFailure() { 088 authenticationFailures.incr(); 089 } 090 091 @Override 092 public void authenticationFallback() { 093 authenticationFallbacks.incr(); 094 } 095 096 @Override 097 public void authenticationSuccess() { 098 authenticationSuccesses.incr(); 099 } 100 101 @Override 102 public void sentBytes(long count) { 103 this.sentBytes.incr(count); 104 } 105 106 @Override 107 public void receivedBytes(int count) { 108 this.receivedBytes.incr(count); 109 } 110 111 @Override 112 public void sentResponse(long count) { 113 this.responseSize.add(count); 114 } 115 116 @Override 117 public void receivedRequest(long count) { 118 this.requestSize.add(count); 119 } 120 121 @Override 122 public void dequeuedCall(int qTime) { 123 queueCallTime.add(qTime); 124 } 125 126 @Override 127 public void processedCall(int processingTime) { 128 processCallTime.add(processingTime); 129 } 130 131 @Override 132 public void queuedAndProcessedCall(int totalTime) { 133 totalCallTime.add(totalTime); 134 } 135 136 @Override 137 public void getMetrics(MetricsCollector metricsCollector, boolean all) { 138 MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName); 139 140 if (wrapper != null) { 141 mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize()) 142 .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC), 143 wrapper.getGeneralQueueLength()) 144 .addGauge(Interns.info(REPLICATION_QUEUE_NAME, REPLICATION_QUEUE_DESC), 145 wrapper.getReplicationQueueLength()) 146 .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC), 147 wrapper.getPriorityQueueLength()) 148 .addGauge(Interns.info(METAPRIORITY_QUEUE_NAME, METAPRIORITY_QUEUE_DESC), 149 wrapper.getMetaPriorityQueueLength()) 150 .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME, NUM_OPEN_CONNECTIONS_DESC), 151 wrapper.getNumOpenConnections()) 152 .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME, NUM_ACTIVE_HANDLER_DESC), 153 wrapper.getActiveRpcHandlerCount()) 154 .addGauge(Interns.info(NUM_ACTIVE_GENERAL_HANDLER_NAME, NUM_ACTIVE_GENERAL_HANDLER_DESC), 155 wrapper.getActiveGeneralRpcHandlerCount()) 156 .addGauge(Interns.info(NUM_ACTIVE_PRIORITY_HANDLER_NAME, NUM_ACTIVE_PRIORITY_HANDLER_DESC), 157 wrapper.getActivePriorityRpcHandlerCount()) 158 .addGauge( 159 Interns.info(NUM_ACTIVE_REPLICATION_HANDLER_NAME, NUM_ACTIVE_REPLICATION_HANDLER_DESC), 160 wrapper.getActiveReplicationRpcHandlerCount()) 161 .addCounter(Interns.info(NUM_GENERAL_CALLS_DROPPED_NAME, NUM_GENERAL_CALLS_DROPPED_DESC), 162 wrapper.getNumGeneralCallsDropped()) 163 .addCounter(Interns.info(NUM_LIFO_MODE_SWITCHES_NAME, NUM_LIFO_MODE_SWITCHES_DESC), 164 wrapper.getNumLifoModeSwitches()) 165 .addGauge(Interns.info(WRITE_QUEUE_NAME, WRITE_QUEUE_DESC), wrapper.getWriteQueueLength()) 166 .addGauge(Interns.info(READ_QUEUE_NAME, READ_QUEUE_DESC), wrapper.getReadQueueLength()) 167 .addGauge(Interns.info(SCAN_QUEUE_NAME, SCAN_QUEUE_DESC), wrapper.getScanQueueLength()) 168 .addGauge(Interns.info(NUM_ACTIVE_WRITE_HANDLER_NAME, NUM_ACTIVE_WRITE_HANDLER_DESC), 169 wrapper.getActiveWriteRpcHandlerCount()) 170 .addGauge(Interns.info(NUM_ACTIVE_READ_HANDLER_NAME, NUM_ACTIVE_READ_HANDLER_DESC), 171 wrapper.getActiveReadRpcHandlerCount()) 172 .addGauge(Interns.info(NUM_ACTIVE_SCAN_HANDLER_NAME, NUM_ACTIVE_SCAN_HANDLER_DESC), 173 wrapper.getActiveScanRpcHandlerCount()) 174 .addGauge(Interns.info(NETTY_DM_USAGE_NAME, NETTY_DM_USAGE_DESC), 175 wrapper.getNettyDmUsage()); 176 } 177 178 metricsRegistry.snapshot(mrb, all); 179 } 180}