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.master;
020
021import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
022import org.apache.hadoop.hbase.metrics.OperationMetrics;
023import org.apache.hadoop.metrics2.MetricHistogram;
024import org.apache.hadoop.metrics2.lib.MutableFastCounter;
025import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
026import org.apache.yetus.audience.InterfaceAudience;
027
028@InterfaceAudience.Private
029public class MetricsAssignmentManagerSourceImpl
030    extends BaseSourceImpl
031    implements MetricsAssignmentManagerSource {
032
033  private MutableGaugeLong ritGauge;
034  private MutableGaugeLong ritCountOverThresholdGauge;
035  private MutableGaugeLong ritOldestAgeGauge;
036  private MetricHistogram ritDurationHisto;
037
038  private MutableFastCounter operationCounter;
039
040  private OperationMetrics assignMetrics;
041  private OperationMetrics unassignMetrics;
042  private OperationMetrics splitMetrics;
043  private OperationMetrics mergeMetrics;
044
045  public MetricsAssignmentManagerSourceImpl() {
046    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
047  }
048
049  public MetricsAssignmentManagerSourceImpl(String metricsName,
050                                            String metricsDescription,
051                                            String metricsContext, String metricsJmxContext) {
052    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
053  }
054
055  public void init() {
056    ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, RIT_COUNT_DESC, 0L);
057    ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME,
058        RIT_COUNT_OVER_THRESHOLD_DESC,0L);
059    ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, RIT_OLDEST_AGE_DESC, 0L);
060    ritDurationHisto = metricsRegistry.newTimeHistogram(RIT_DURATION_NAME, RIT_DURATION_DESC);
061    operationCounter = metricsRegistry.getCounter(OPERATION_COUNT_NAME, 0L);
062
063    /**
064     * NOTE: Please refer to HBASE-9774 and HBASE-14282. Based on these two issues, HBase is
065     * moving away from using Hadoop's metric2 to having independent HBase specific Metrics. Use
066     * {@link BaseSourceImpl#registry} to register the new metrics.
067     */
068    assignMetrics = new OperationMetrics(registry, ASSIGN_METRIC_PREFIX);
069    unassignMetrics = new OperationMetrics(registry, UNASSIGN_METRIC_PREFIX);
070    splitMetrics = new OperationMetrics(registry, SPLIT_METRIC_PREFIX);
071    mergeMetrics = new OperationMetrics(registry, MERGE_METRIC_PREFIX);
072  }
073
074  @Override
075  public void setRIT(final int ritCount) {
076    ritGauge.set(ritCount);
077  }
078
079  @Override
080  public void setRITCountOverThreshold(final int ritCount) {
081    ritCountOverThresholdGauge.set(ritCount);
082  }
083
084  @Override
085  public void setRITOldestAge(final long ritCount) {
086    ritOldestAgeGauge.set(ritCount);
087  }
088
089  @Override
090  public void incrementOperationCounter() {
091    operationCounter.incr();
092  }
093
094  @Override
095  public void updateRitDuration(long duration) {
096    ritDurationHisto.add(duration);
097  }
098
099  @Override
100  public OperationMetrics getAssignMetrics() {
101    return assignMetrics;
102  }
103
104  @Override
105  public OperationMetrics getUnassignMetrics() {
106    return unassignMetrics;
107  }
108
109  @Override
110  public OperationMetrics getSplitMetrics() {
111    return splitMetrics;
112  }
113
114  @Override
115  public OperationMetrics getMergeMetrics() {
116    return mergeMetrics;
117  }
118}