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 */
018package org.apache.hadoop.hbase.metrics;
019
020import org.apache.hadoop.metrics2.lib.MutableFastCounter;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * Common base implementation for metrics sources which need to track exceptions thrown or received.
025 */
026@InterfaceAudience.Private
027public class ExceptionTrackingSourceImpl extends BaseSourceImpl implements ExceptionTrackingSource {
028  protected MutableFastCounter exceptions;
029  protected MutableFastCounter exceptionsOOO;
030  protected MutableFastCounter exceptionsBusy;
031  protected MutableFastCounter exceptionsUnknown;
032  protected MutableFastCounter exceptionsScannerReset;
033  protected MutableFastCounter exceptionsSanity;
034  protected MutableFastCounter exceptionsNSRE;
035  protected MutableFastCounter exceptionsMoved;
036  protected MutableFastCounter exceptionsMultiTooLarge;
037  protected MutableFastCounter exceptionsCallQueueTooBig;
038  protected MutableFastCounter exceptionsQuotaExceeded;
039  protected MutableFastCounter exceptionsRpcThrottling;
040  protected MutableFastCounter exceptionsCallDropped;
041  protected MutableFastCounter exceptionsCallTimedOut;
042  protected MutableFastCounter exceptionRequestTooBig;
043  protected MutableFastCounter otherExceptions;
044
045  public ExceptionTrackingSourceImpl(String metricsName, String metricsDescription,
046    String metricsContext, String metricsJmxContext) {
047    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
048  }
049
050  @Override
051  public void init() {
052    super.init();
053    this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
054    this.exceptionsOOO =
055      this.getMetricsRegistry().newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
056    this.exceptionsBusy =
057      this.getMetricsRegistry().newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
058    this.exceptionsUnknown =
059      this.getMetricsRegistry().newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
060    this.exceptionsScannerReset =
061      this.getMetricsRegistry().newCounter(EXCEPTIONS_SCANNER_RESET_NAME, EXCEPTIONS_TYPE_DESC, 0L);
062    this.exceptionsSanity =
063      this.getMetricsRegistry().newCounter(EXCEPTIONS_SANITY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
064    this.exceptionsMoved =
065      this.getMetricsRegistry().newCounter(EXCEPTIONS_MOVED_NAME, EXCEPTIONS_TYPE_DESC, 0L);
066    this.exceptionsNSRE =
067      this.getMetricsRegistry().newCounter(EXCEPTIONS_NSRE_NAME, EXCEPTIONS_TYPE_DESC, 0L);
068    this.exceptionsMultiTooLarge = this.getMetricsRegistry()
069      .newCounter(EXCEPTIONS_MULTI_TOO_LARGE_NAME, EXCEPTIONS_MULTI_TOO_LARGE_DESC, 0L);
070    this.exceptionsCallQueueTooBig = this.getMetricsRegistry()
071      .newCounter(EXCEPTIONS_CALL_QUEUE_TOO_BIG, EXCEPTIONS_CALL_QUEUE_TOO_BIG_DESC, 0L);
072    this.exceptionsQuotaExceeded =
073      this.getMetricsRegistry().newCounter(EXCEPTIONS_QUOTA_EXCEEDED, EXCEPTIONS_TYPE_DESC, 0L);
074    this.exceptionsRpcThrottling =
075      this.getMetricsRegistry().newCounter(EXCEPTIONS_RPC_THROTTLING, EXCEPTIONS_TYPE_DESC, 0L);
076    this.exceptionsCallDropped =
077      this.getMetricsRegistry().newCounter(EXCEPTIONS_CALL_DROPPED, EXCEPTIONS_TYPE_DESC, 0L);
078    this.exceptionsCallTimedOut =
079      this.getMetricsRegistry().newCounter(EXCEPTIONS_CALL_TIMED_OUT, EXCEPTIONS_TYPE_DESC, 0L);
080    this.exceptionRequestTooBig =
081      this.getMetricsRegistry().newCounter(EXCEPTIONS_REQUEST_TOO_BIG, EXCEPTIONS_TYPE_DESC, 0L);
082    this.otherExceptions =
083      this.getMetricsRegistry().newCounter(OTHER_EXCEPTIONS, EXCEPTIONS_TYPE_DESC, 0L);
084  }
085
086  @Override
087  public void exception() {
088    exceptions.incr();
089  }
090
091  @Override
092  public void outOfOrderException() {
093    exceptionsOOO.incr();
094  }
095
096  @Override
097  public void failedSanityException() {
098    exceptionsSanity.incr();
099  }
100
101  @Override
102  public void movedRegionException() {
103    exceptionsMoved.incr();
104  }
105
106  @Override
107  public void notServingRegionException() {
108    exceptionsNSRE.incr();
109  }
110
111  @Override
112  public void unknownScannerException() {
113    exceptionsUnknown.incr();
114  }
115
116  @Override
117  public void scannerResetException() {
118    exceptionsScannerReset.incr();
119  }
120
121  @Override
122  public void tooBusyException() {
123    exceptionsBusy.incr();
124  }
125
126  @Override
127  public void multiActionTooLargeException() {
128    exceptionsMultiTooLarge.incr();
129  }
130
131  @Override
132  public void callQueueTooBigException() {
133    exceptionsCallQueueTooBig.incr();
134  }
135
136  @Override
137  public void quotaExceededException() {
138    exceptionsQuotaExceeded.incr();
139  }
140
141  @Override
142  public void rpcThrottlingException() {
143    exceptionsRpcThrottling.incr();
144  }
145
146  @Override
147  public void callDroppedException() {
148    exceptionsCallDropped.incr();
149  }
150
151  @Override
152  public void callTimedOut() {
153    exceptionsCallTimedOut.incr();
154  }
155
156  @Override
157  public void requestTooBigException() {
158    exceptionRequestTooBig.incr();
159  }
160
161  @Override
162  public void otherExceptions() {
163    otherExceptions.incr();
164  }
165}