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.metrics;
020
021import org.apache.hadoop.metrics2.lib.MutableFastCounter;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * Common base implementation for metrics sources which need to track exceptions thrown or
026 * received.
027 */
028@InterfaceAudience.Private
029public class ExceptionTrackingSourceImpl extends BaseSourceImpl
030    implements ExceptionTrackingSource {
031  protected MutableFastCounter exceptions;
032  protected MutableFastCounter exceptionsOOO;
033  protected MutableFastCounter exceptionsBusy;
034  protected MutableFastCounter exceptionsUnknown;
035  protected MutableFastCounter exceptionsScannerReset;
036  protected MutableFastCounter exceptionsSanity;
037  protected MutableFastCounter exceptionsNSRE;
038  protected MutableFastCounter exceptionsMoved;
039  protected MutableFastCounter exceptionsMultiTooLarge;
040  protected MutableFastCounter exceptionsCallQueueTooBig;
041
042  public ExceptionTrackingSourceImpl(String metricsName, String metricsDescription,
043                                     String metricsContext, String metricsJmxContext) {
044    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
045  }
046
047  @Override
048  public void init() {
049    super.init();
050    this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
051    this.exceptionsOOO = this.getMetricsRegistry()
052        .newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
053    this.exceptionsBusy = this.getMetricsRegistry()
054        .newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
055    this.exceptionsUnknown = this.getMetricsRegistry()
056        .newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
057    this.exceptionsScannerReset = this.getMetricsRegistry()
058        .newCounter(EXCEPTIONS_SCANNER_RESET_NAME, EXCEPTIONS_TYPE_DESC, 0L);
059    this.exceptionsSanity = this.getMetricsRegistry()
060        .newCounter(EXCEPTIONS_SANITY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
061    this.exceptionsMoved = this.getMetricsRegistry()
062        .newCounter(EXCEPTIONS_MOVED_NAME, EXCEPTIONS_TYPE_DESC, 0L);
063    this.exceptionsNSRE = this.getMetricsRegistry()
064        .newCounter(EXCEPTIONS_NSRE_NAME, EXCEPTIONS_TYPE_DESC, 0L);
065    this.exceptionsMultiTooLarge = this.getMetricsRegistry()
066        .newCounter(EXCEPTIONS_MULTI_TOO_LARGE_NAME, EXCEPTIONS_MULTI_TOO_LARGE_DESC, 0L);
067    this.exceptionsCallQueueTooBig = this.getMetricsRegistry()
068        .newCounter(EXCEPTIONS_CALL_QUEUE_TOO_BIG, EXCEPTIONS_CALL_QUEUE_TOO_BIG_DESC, 0L);
069  }
070
071  @Override
072  public void exception() {
073    exceptions.incr();
074  }
075
076  @Override
077  public void outOfOrderException() {
078    exceptionsOOO.incr();
079  }
080
081  @Override
082  public void failedSanityException() {
083    exceptionsSanity.incr();
084  }
085
086  @Override
087  public void movedRegionException() {
088    exceptionsMoved.incr();
089  }
090
091  @Override
092  public void notServingRegionException() {
093    exceptionsNSRE.incr();
094  }
095
096  @Override
097  public void unknownScannerException() {
098    exceptionsUnknown.incr();
099  }
100
101  @Override
102  public void scannerResetException() {
103    exceptionsScannerReset.incr();
104  }
105
106  @Override
107  public void tooBusyException() {
108    exceptionsBusy.incr();
109  }
110
111  @Override
112  public void multiActionTooLargeException() {
113    exceptionsMultiTooLarge.incr();
114  }
115
116  @Override
117  public void callQueueTooBigException() {
118    exceptionsCallQueueTooBig.incr();
119  }
120}