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.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.MetricHistogram;
24  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
25  
26  
27  /**
28   * Class that transitions metrics from MetricsWAL into the metrics subsystem.
29   *
30   * Implements BaseSource through BaseSourceImpl, following the pattern.
31   * @see org.apache.hadoop.hbase.regionserver.wal.MetricsWAL
32   */
33  @InterfaceAudience.Private
34  public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSource {
35  
36    private final MetricHistogram appendSizeHisto;
37    private final MetricHistogram appendTimeHisto;
38    private final MetricHistogram syncTimeHisto;
39    private final MutableCounterLong appendCount;
40    private final MutableCounterLong slowAppendCount;
41  
42    public MetricsWALSourceImpl() {
43      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
44    }
45  
46    public MetricsWALSourceImpl(String metricsName,
47                                String metricsDescription,
48                                String metricsContext,
49                                String metricsJmxContext) {
50      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
51  
52      //Create and store the metrics that will be used.
53      appendTimeHisto = this.getMetricsRegistry().newHistogram(APPEND_TIME, APPEND_TIME_DESC);
54      appendSizeHisto = this.getMetricsRegistry().newHistogram(APPEND_SIZE, APPEND_SIZE_DESC);
55      appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0l);
56      slowAppendCount = this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0l);
57      syncTimeHisto = this.getMetricsRegistry().newHistogram(SYNC_TIME, SYNC_TIME_DESC);
58    }
59  
60    @Override
61    public void incrementAppendSize(long size) {
62      appendSizeHisto.add(size);
63    }
64  
65    @Override
66    public void incrementAppendTime(long time) {
67      appendTimeHisto.add(time);
68    }
69  
70    @Override
71    public void incrementAppendCount() {
72      appendCount.incr();
73    }
74  
75    @Override
76    public void incrementSlowAppendCount() {
77      slowAppendCount.incr();
78    }
79  
80    @Override
81    public void incrementSyncTime(long time) {
82      syncTimeHisto.add(time);
83    }
84  }