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.regionserver.wal;
020
021import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
022import org.apache.hadoop.metrics2.MetricHistogram;
023import org.apache.hadoop.metrics2.lib.MutableFastCounter;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * Class that transitions metrics from MetricsWAL into the metrics subsystem.
028 *
029 * Implements BaseSource through BaseSourceImpl, following the pattern.
030 * @see org.apache.hadoop.hbase.regionserver.wal.MetricsWALSource
031 */
032@InterfaceAudience.Private
033public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSource {
034
035  private final MetricHistogram appendSizeHisto;
036  private final MetricHistogram appendTimeHisto;
037  private final MetricHistogram syncTimeHisto;
038  private final MutableFastCounter appendCount;
039  private final MutableFastCounter slowAppendCount;
040  private final MutableFastCounter logRollRequested;
041  private final MutableFastCounter lowReplicationLogRollRequested;
042  private final MutableFastCounter writtenBytes;
043
044  public MetricsWALSourceImpl() {
045    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
046  }
047
048  public MetricsWALSourceImpl(String metricsName,
049                              String metricsDescription,
050                              String metricsContext,
051                              String metricsJmxContext) {
052    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
053
054    //Create and store the metrics that will be used.
055    appendTimeHisto = this.getMetricsRegistry().newTimeHistogram(APPEND_TIME, APPEND_TIME_DESC);
056    appendSizeHisto = this.getMetricsRegistry().newSizeHistogram(APPEND_SIZE, APPEND_SIZE_DESC);
057    appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0L);
058    slowAppendCount =
059        this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0L);
060    syncTimeHisto = this.getMetricsRegistry().newTimeHistogram(SYNC_TIME, SYNC_TIME_DESC);
061    logRollRequested =
062        this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L);
063    lowReplicationLogRollRequested = this.getMetricsRegistry()
064        .newCounter(LOW_REPLICA_ROLL_REQUESTED, LOW_REPLICA_ROLL_REQUESTED_DESC, 0L);
065    writtenBytes = this.getMetricsRegistry().newCounter(WRITTEN_BYTES, WRITTEN_BYTES_DESC, 0L);
066  }
067
068  @Override
069  public void incrementAppendSize(long size) {
070    appendSizeHisto.add(size);
071  }
072
073  @Override
074  public void incrementAppendTime(long time) {
075    appendTimeHisto.add(time);
076  }
077
078  @Override
079  public void incrementAppendCount() {
080    appendCount.incr();
081  }
082
083  @Override
084  public void incrementSlowAppendCount() {
085    slowAppendCount.incr();
086  }
087
088  @Override
089  public void incrementSyncTime(long time) {
090    syncTimeHisto.add(time);
091  }
092
093  @Override
094  public void incrementLogRollRequested() {
095    logRollRequested.incr();
096  }
097
098  @Override
099  public void incrementLowReplicationLogRoll() {
100    lowReplicationLogRollRequested.incr();
101  }
102
103  @Override
104  public long getSlowAppendCount() {
105    return slowAppendCount.value();
106  }
107
108  @Override
109  public void incrementWrittenBytes(long val) {
110    writtenBytes.incr(val);
111  }
112
113  @Override
114  public long getWrittenBytes() {
115    return writtenBytes.value();
116  }
117
118}