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