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