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.metrics2.MetricHistogram;
023import org.apache.yetus.audience.InterfaceAudience;
024
025@InterfaceAudience.Private
026public class MetricsSnapshotSourceImpl extends BaseSourceImpl implements MetricsSnapshotSource {
027
028  private MetricHistogram snapshotTimeHisto;
029  private MetricHistogram snapshotCloneTimeHisto;
030  private MetricHistogram snapshotRestoreTimeHisto;
031
032  public MetricsSnapshotSourceImpl() {
033    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
034  }
035
036  public MetricsSnapshotSourceImpl(String metricsName,
037                                   String metricsDescription,
038                                   String metricsContext, String metricsJmxContext) {
039    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
040  }
041
042  @Override
043  public void init() {
044    snapshotTimeHisto = metricsRegistry.newTimeHistogram(
045        SNAPSHOT_TIME_NAME, SNAPSHOT_TIME_DESC);
046    snapshotCloneTimeHisto = metricsRegistry.newTimeHistogram(
047        SNAPSHOT_CLONE_TIME_NAME, SNAPSHOT_CLONE_TIME_DESC);
048    snapshotRestoreTimeHisto = metricsRegistry.newTimeHistogram(
049        SNAPSHOT_RESTORE_TIME_NAME, SNAPSHOT_RESTORE_TIME_DESC);
050  }
051
052  @Override
053  public void updateSnapshotTime(long time) {
054    snapshotTimeHisto.add(time);
055  }
056
057  @Override
058  public void updateSnapshotCloneTime(long time) {
059    snapshotCloneTimeHisto.add(time);
060  }
061
062  @Override
063  public void updateSnapshotRestoreTime(long time) {
064    snapshotRestoreTimeHisto.add(time);
065  }
066}