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.metrics;
20  
21  import org.apache.hadoop.metrics2.lib.MutableFastCounter;
22  
23  /**
24   * Common base implementation for metrics sources which need to track exceptions thrown or
25   * received.
26   */
27  public class ExceptionTrackingSourceImpl extends BaseSourceImpl
28      implements ExceptionTrackingSource {
29    protected MutableFastCounter exceptions;
30    protected MutableFastCounter exceptionsOOO;
31    protected MutableFastCounter exceptionsBusy;
32    protected MutableFastCounter exceptionsUnknown;
33    protected MutableFastCounter exceptionsScannerReset;
34    protected MutableFastCounter exceptionsSanity;
35    protected MutableFastCounter exceptionsNSRE;
36    protected MutableFastCounter exceptionsMoved;
37    protected MutableFastCounter exceptionsMultiTooLarge;
38    protected MutableFastCounter exceptionsCallQueueTooBig;
39  
40    public ExceptionTrackingSourceImpl(String metricsName, String metricsDescription,
41                                       String metricsContext, String metricsJmxContext) {
42      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
43    }
44  
45    @Override
46    public void init() {
47      super.init();
48      this.exceptions = this.getMetricsRegistry().newCounter(EXCEPTIONS_NAME, EXCEPTIONS_DESC, 0L);
49      this.exceptionsOOO = this.getMetricsRegistry()
50          .newCounter(EXCEPTIONS_OOO_NAME, EXCEPTIONS_TYPE_DESC, 0L);
51      this.exceptionsBusy = this.getMetricsRegistry()
52          .newCounter(EXCEPTIONS_BUSY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
53      this.exceptionsUnknown = this.getMetricsRegistry()
54          .newCounter(EXCEPTIONS_UNKNOWN_NAME, EXCEPTIONS_TYPE_DESC, 0L);
55      this.exceptionsScannerReset = this.getMetricsRegistry()
56          .newCounter(EXCEPTIONS_SCANNER_RESET_NAME, EXCEPTIONS_TYPE_DESC, 0L);
57      this.exceptionsSanity = this.getMetricsRegistry()
58          .newCounter(EXCEPTIONS_SANITY_NAME, EXCEPTIONS_TYPE_DESC, 0L);
59      this.exceptionsMoved = this.getMetricsRegistry()
60          .newCounter(EXCEPTIONS_MOVED_NAME, EXCEPTIONS_TYPE_DESC, 0L);
61      this.exceptionsNSRE = this.getMetricsRegistry()
62          .newCounter(EXCEPTIONS_NSRE_NAME, EXCEPTIONS_TYPE_DESC, 0L);
63      this.exceptionsMultiTooLarge = this.getMetricsRegistry()
64          .newCounter(EXCEPTIONS_MULTI_TOO_LARGE_NAME, EXCEPTIONS_MULTI_TOO_LARGE_DESC, 0L);
65      this.exceptionsCallQueueTooBig = this.getMetricsRegistry()
66          .newCounter(EXCEPTIONS_CALL_QUEUE_TOO_BIG, EXCEPTIONS_CALL_QUEUE_TOO_BIG_DESC, 0L);
67    }
68  
69    @Override
70    public void exception() {
71      exceptions.incr();
72    }
73  
74    @Override
75    public void outOfOrderException() {
76      exceptionsOOO.incr();
77    }
78  
79    @Override
80    public void failedSanityException() {
81      exceptionsSanity.incr();
82    }
83  
84    @Override
85    public void movedRegionException() {
86      exceptionsMoved.incr();
87    }
88  
89    @Override
90    public void notServingRegionException() {
91      exceptionsNSRE.incr();
92    }
93  
94    @Override
95    public void unknownScannerException() {
96      exceptionsUnknown.incr();
97    }
98  
99    @Override
100   public void scannerResetException() {
101     exceptionsScannerReset.incr();
102   }
103 
104   @Override
105   public void tooBusyException() {
106     exceptionsBusy.incr();
107   }
108 
109   @Override
110   public void multiActionTooLargeException() {
111     exceptionsMultiTooLarge.incr();
112   }
113 
114   @Override
115   public void callQueueTooBigException() {
116     exceptionsCallQueueTooBig.incr();
117   }
118 }