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  private MutableGaugeLong deadServerOpenRegions;
038  private MutableGaugeLong unknownServerOpenRegions;
039
040  private MutableFastCounter operationCounter;
041
042  private OperationMetrics assignMetrics;
043  private OperationMetrics unassignMetrics;
044  private OperationMetrics moveMetrics;
045  private OperationMetrics reopenMetrics;
046  private OperationMetrics openMetrics;
047  private OperationMetrics closeMetrics;
048  private OperationMetrics splitMetrics;
049  private OperationMetrics mergeMetrics;
050
051  public MetricsAssignmentManagerSourceImpl() {
052    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
053  }
054
055  public MetricsAssignmentManagerSourceImpl(String metricsName,
056                                            String metricsDescription,
057                                            String metricsContext, String metricsJmxContext) {
058    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
059  }
060
061  public void init() {
062    ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, RIT_COUNT_DESC, 0L);
063    ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME,
064        RIT_COUNT_OVER_THRESHOLD_DESC,0L);
065    ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, RIT_OLDEST_AGE_DESC, 0L);
066    ritDurationHisto = metricsRegistry.newTimeHistogram(RIT_DURATION_NAME, RIT_DURATION_DESC);
067    operationCounter = metricsRegistry.getCounter(OPERATION_COUNT_NAME, 0L);
068    deadServerOpenRegions = metricsRegistry.newGauge(DEAD_SERVER_OPEN_REGIONS, "", 0);
069    unknownServerOpenRegions = metricsRegistry.newGauge(UNKNOWN_SERVER_OPEN_REGIONS, "", 0);
070
071    /**
072     * NOTE: Please refer to HBASE-9774 and HBASE-14282. Based on these two issues, HBase is
073     * moving away from using Hadoop's metric2 to having independent HBase specific Metrics. Use
074     * {@link BaseSourceImpl#registry} to register the new metrics.
075     */
076    assignMetrics = new OperationMetrics(registry, ASSIGN_METRIC_PREFIX);
077    unassignMetrics = new OperationMetrics(registry, UNASSIGN_METRIC_PREFIX);
078    moveMetrics = new OperationMetrics(registry, MOVE_METRIC_PREFIX);
079    reopenMetrics = new OperationMetrics(registry, REOPEN_METRIC_PREFIX);
080    openMetrics = new OperationMetrics(registry, OPEN_METRIC_PREFIX);
081    closeMetrics = new OperationMetrics(registry, CLOSE_METRIC_PREFIX);
082    splitMetrics = new OperationMetrics(registry, SPLIT_METRIC_PREFIX);
083    mergeMetrics = new OperationMetrics(registry, MERGE_METRIC_PREFIX);
084  }
085
086  @Override
087  public void setRIT(final int ritCount) {
088    ritGauge.set(ritCount);
089  }
090
091  @Override
092  public void setRITCountOverThreshold(final int ritCount) {
093    ritCountOverThresholdGauge.set(ritCount);
094  }
095
096  @Override
097  public void setRITOldestAge(final long ritOldestAge) {
098    ritOldestAgeGauge.set(ritOldestAge);
099  }
100
101  @Override
102  public void incrementOperationCounter() {
103    operationCounter.incr();
104  }
105
106  @Override
107  public void updateRitDuration(long duration) {
108    ritDurationHisto.add(duration);
109  }
110
111  @Override
112  public void updateDeadServerOpenRegions(int deadRegions) {
113    deadServerOpenRegions.set(deadRegions);
114  }
115
116  @Override
117  public void updateUnknownServerOpenRegions(int unknownRegions) {
118    unknownServerOpenRegions.set(unknownRegions);
119  }
120
121  @Override
122  public OperationMetrics getAssignMetrics() {
123    return assignMetrics;
124  }
125
126  @Override
127  public OperationMetrics getUnassignMetrics() {
128    return unassignMetrics;
129  }
130
131  @Override
132  public OperationMetrics getSplitMetrics() {
133    return splitMetrics;
134  }
135
136  @Override
137  public OperationMetrics getMergeMetrics() {
138    return mergeMetrics;
139  }
140
141  @Override
142  public OperationMetrics getMoveMetrics() {
143    return moveMetrics;
144  }
145
146  @Override
147  public OperationMetrics getReopenMetrics() {
148    return reopenMetrics;
149  }
150
151  @Override
152  public OperationMetrics getOpenMetrics() {
153    return openMetrics;
154  }
155
156  @Override
157  public OperationMetrics getCloseMetrics() {
158    return closeMetrics;
159  }
160}