View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.regionserver.wal;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
25  import org.apache.hadoop.metrics2.MetricHistogram;
26  
27  /**
28   * Hadoop1 implementation of MetricsMasterSource. Implements BaseSource through BaseSourceImpl,
29   * following the pattern
30   */
31  @InterfaceAudience.Private
32  public class MetricsEditsReplaySourceImpl extends BaseSourceImpl implements
33      MetricsEditsReplaySource {
34  
35    private static final Log LOG = LogFactory.getLog(MetricsEditsReplaySourceImpl.class.getName());
36  
37    private MetricHistogram replayTimeHisto;
38    private MetricHistogram replayBatchSizeHisto;
39    private MetricHistogram replayDataSizeHisto;
40  
41    public MetricsEditsReplaySourceImpl() {
42      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
43    }
44  
45    public MetricsEditsReplaySourceImpl(String metricsName,
46                                        String metricsDescription,
47                                        String metricsContext,
48                                        String metricsJmxContext) {
49      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
50    }
51  
52    @Override
53    public void init() {
54      super.init();
55      replayTimeHisto = metricsRegistry.newTimeHistogram(REPLAY_TIME_NAME, REPLAY_TIME_DESC);
56      replayBatchSizeHisto = metricsRegistry.newSizeHistogram(REPLAY_BATCH_SIZE_NAME,
57        REPLAY_BATCH_SIZE_DESC);
58      replayDataSizeHisto = metricsRegistry
59          .newSizeHistogram(REPLAY_DATA_SIZE_NAME, REPLAY_DATA_SIZE_DESC);
60    }
61  
62    @Override
63    public void updateReplayTime(long time) {
64      replayTimeHisto.add(time);
65    }
66  
67    @Override
68    public void updateReplayBatchSize(long size) {
69      replayBatchSizeHisto.add(size);
70    }
71  
72    @Override
73    public void updateReplayDataSize(long size) {
74      replayDataSizeHisto.add(size);
75    }
76  }