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 */ 018 019package org.apache.hadoop.hbase.thrift; 020 021import org.apache.hadoop.hbase.metrics.ExceptionTrackingSourceImpl; 022import org.apache.hadoop.metrics2.MetricHistogram; 023import org.apache.hadoop.metrics2.lib.MutableFastCounter; 024import org.apache.hadoop.metrics2.lib.MutableGaugeLong; 025import org.apache.hadoop.metrics2.lib.MutableHistogram; 026import org.apache.yetus.audience.InterfaceAudience; 027 028/** 029 * Hadoop 2 version of {@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource} 030 * 031 * Implements BaseSource through BaseSourceImpl, following the pattern 032 */ 033@InterfaceAudience.Private 034public class MetricsThriftServerSourceImpl extends ExceptionTrackingSourceImpl implements 035 MetricsThriftServerSource { 036 037 private MetricHistogram batchGetStat; 038 private MetricHistogram batchMutateStat; 039 private MetricHistogram queueTimeStat; 040 041 private MetricHistogram thriftCallStat; 042 private MetricHistogram thriftSlowCallStat; 043 044 private MutableGaugeLong callQueueLenGauge; 045 046 private MutableGaugeLong activeWorkerCountGauge; 047 048 // pause monitor metrics 049 private final MutableFastCounter infoPauseThresholdExceeded; 050 private final MutableFastCounter warnPauseThresholdExceeded; 051 private final MetricHistogram pausesWithGc; 052 private final MetricHistogram pausesWithoutGc; 053 054 public MetricsThriftServerSourceImpl(String metricsName, 055 String metricsDescription, 056 String metricsContext, 057 String metricsJmxContext) { 058 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 059 060 // pause monitor metrics 061 infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY, 062 INFO_THRESHOLD_COUNT_DESC, 0L); 063 warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY, 064 WARN_THRESHOLD_COUNT_DESC, 0L); 065 pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY); 066 pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY); 067 } 068 069 @Override 070 public void init() { 071 super.init(); 072 batchGetStat = getMetricsRegistry().newTimeHistogram(BATCH_GET_KEY); 073 batchMutateStat = getMetricsRegistry().newTimeHistogram(BATCH_MUTATE_KEY); 074 queueTimeStat = getMetricsRegistry().newTimeHistogram(TIME_IN_QUEUE_KEY); 075 thriftCallStat = getMetricsRegistry().newTimeHistogram(THRIFT_CALL_KEY); 076 thriftSlowCallStat = getMetricsRegistry().newTimeHistogram(SLOW_THRIFT_CALL_KEY); 077 callQueueLenGauge = getMetricsRegistry().getGauge(CALL_QUEUE_LEN_KEY, 0); 078 activeWorkerCountGauge = getMetricsRegistry().getGauge(ACTIVE_WORKER_COUNT_KEY, 0); 079 } 080 081 @Override 082 public void incTimeInQueue(long time) { 083 queueTimeStat.add(time); 084 } 085 086 @Override 087 public void setCallQueueLen(int len) { 088 callQueueLenGauge.set(len); 089 } 090 091 @Override 092 public void incNumRowKeysInBatchGet(int diff) { 093 batchGetStat.add(diff); 094 } 095 096 @Override 097 public void incNumRowKeysInBatchMutate(int diff) { 098 batchMutateStat.add(diff); 099 } 100 101 @Override 102 public void incMethodTime(String name, long time) { 103 MutableHistogram s = getMetricsRegistry().getHistogram(name); 104 s.add(time); 105 } 106 107 @Override 108 public void incCall(long time) { 109 thriftCallStat.add(time); 110 } 111 112 @Override 113 public void incSlowCall(long time) { 114 thriftSlowCallStat.add(time); 115 } 116 117 @Override 118 public void incActiveWorkerCount() { 119 activeWorkerCountGauge.incr(); 120 } 121 122 @Override 123 public void decActiveWorkerCount() { 124 activeWorkerCountGauge.decr(); 125 } 126 127 @Override 128 public void incInfoThresholdExceeded(int count) { 129 infoPauseThresholdExceeded.incr(count); 130 } 131 132 @Override 133 public void incWarnThresholdExceeded(int count) { 134 warnPauseThresholdExceeded.incr(count); 135 } 136 137 @Override 138 public void updatePauseTimeWithGc(long t) { 139 pausesWithGc.add(t); 140 } 141 142 @Override 143 public void updatePauseTimeWithoutGc(long t) { 144 pausesWithoutGc.add(t); 145 } 146}