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 errorRollRequested;
042  private final MutableFastCounter lowReplicationRollRequested;
043  private final MutableFastCounter slowSyncRollRequested;
044  private final MutableFastCounter sizeRollRequested;
045  private final MutableFastCounter writtenBytes;
046
047  public MetricsWALSourceImpl() {
048    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
049  }
050
051  public MetricsWALSourceImpl(String metricsName,
052                              String metricsDescription,
053                              String metricsContext,
054                              String metricsJmxContext) {
055    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
056
057    //Create and store the metrics that will be used.
058    appendTimeHisto = this.getMetricsRegistry().newTimeHistogram(APPEND_TIME, APPEND_TIME_DESC);
059    appendSizeHisto = this.getMetricsRegistry().newSizeHistogram(APPEND_SIZE, APPEND_SIZE_DESC);
060    appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0L);
061    slowAppendCount =
062        this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0L);
063    syncTimeHisto = this.getMetricsRegistry().newTimeHistogram(SYNC_TIME, SYNC_TIME_DESC);
064    logRollRequested =
065        this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L);
066    errorRollRequested = this.getMetricsRegistry()
067        .newCounter(ERROR_ROLL_REQUESTED, ERROR_ROLL_REQUESTED_DESC, 0L);
068    lowReplicationRollRequested = this.getMetricsRegistry()
069        .newCounter(LOW_REPLICA_ROLL_REQUESTED, LOW_REPLICA_ROLL_REQUESTED_DESC, 0L);
070    slowSyncRollRequested = this.getMetricsRegistry()
071        .newCounter(SLOW_SYNC_ROLL_REQUESTED, SLOW_SYNC_ROLL_REQUESTED_DESC, 0L);
072    sizeRollRequested = this.getMetricsRegistry()
073        .newCounter(SIZE_ROLL_REQUESTED, SIZE_ROLL_REQUESTED_DESC, 0L);
074    writtenBytes = this.getMetricsRegistry().newCounter(WRITTEN_BYTES, WRITTEN_BYTES_DESC, 0L);
075  }
076
077  @Override
078  public void incrementAppendSize(long size) {
079    appendSizeHisto.add(size);
080  }
081
082  @Override
083  public void incrementAppendTime(long time) {
084    appendTimeHisto.add(time);
085  }
086
087  @Override
088  public void incrementAppendCount() {
089    appendCount.incr();
090  }
091
092  @Override
093  public void incrementSlowAppendCount() {
094    slowAppendCount.incr();
095  }
096
097  @Override
098  public void incrementSyncTime(long time) {
099    syncTimeHisto.add(time);
100  }
101
102  @Override
103  public void incrementLogRollRequested() {
104    logRollRequested.incr();
105  }
106
107  @Override
108  public void incrementErrorLogRoll() {
109    errorRollRequested.incr();
110  }
111
112  @Override
113  public void incrementLowReplicationLogRoll() {
114    lowReplicationRollRequested.incr();
115  }
116
117  @Override
118  public void incrementSlowSyncLogRoll() {
119    slowSyncRollRequested.incr();
120  }
121
122  @Override
123  public void incrementSizeLogRoll() {
124    sizeRollRequested.incr();
125  }
126
127  @Override
128  public long getSlowAppendCount() {
129    return slowAppendCount.value();
130  }
131
132  @Override
133  public void incrementWrittenBytes(long val) {
134    writtenBytes.incr(val);
135  }
136
137  @Override
138  public long getWrittenBytes() {
139    return writtenBytes.value();
140  }
141
142}