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.rest;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.MetricHistogram;
24  import org.apache.hadoop.metrics2.lib.MutableFastCounter;
25  
26  /**
27   * Hadoop Two implementation of a metrics2 source that will export metrics from the Rest server to
28   * the hadoop metrics2 subsystem.
29   *
30   * Implements BaseSource through BaseSourceImpl, following the pattern
31   */
32  @InterfaceAudience.Private
33  public class MetricsRESTSourceImpl extends BaseSourceImpl implements MetricsRESTSource {
34  
35    private MutableFastCounter request;
36    private MutableFastCounter sucGet;
37    private MutableFastCounter sucPut;
38    private MutableFastCounter sucDel;
39    private MutableFastCounter sucScan;
40    private MutableFastCounter fGet;
41    private MutableFastCounter fPut;
42    private MutableFastCounter fDel;
43    private MutableFastCounter fScan;
44  
45    // pause monitor metrics
46    private final MutableFastCounter infoPauseThresholdExceeded;
47    private final MutableFastCounter warnPauseThresholdExceeded;
48    private final MetricHistogram pausesWithGc;
49    private final MetricHistogram pausesWithoutGc;
50  
51    public MetricsRESTSourceImpl() {
52      this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
53    }
54  
55    public MetricsRESTSourceImpl(String metricsName,
56                                 String metricsDescription,
57                                 String metricsContext,
58                                 String metricsJmxContext) {
59      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
60  
61      // pause monitor metrics
62      infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
63        INFO_THRESHOLD_COUNT_DESC, 0L);
64      warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
65        WARN_THRESHOLD_COUNT_DESC, 0L);
66      pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
67      pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
68    }
69  
70    @Override
71    public void init() {
72      super.init();
73      request = getMetricsRegistry().getCounter(REQUEST_KEY, 0l);
74  
75      sucGet = getMetricsRegistry().getCounter(SUCCESSFUL_GET_KEY, 0l);
76      sucPut = getMetricsRegistry().getCounter(SUCCESSFUL_PUT_KEY, 0l);
77      sucDel = getMetricsRegistry().getCounter(SUCCESSFUL_DELETE_KEY, 0l);
78      sucScan = getMetricsRegistry().getCounter(SUCCESSFUL_SCAN_KEY, 0L);
79  
80      fGet = getMetricsRegistry().getCounter(FAILED_GET_KEY, 0l);
81      fPut = getMetricsRegistry().getCounter(FAILED_PUT_KEY, 0l);
82      fDel = getMetricsRegistry().getCounter(FAILED_DELETE_KEY, 0l);
83      fScan = getMetricsRegistry().getCounter(FAILED_SCAN_KEY, 0l);
84    }
85  
86    @Override
87    public void incrementRequests(int inc) {
88      request.incr(inc);
89    }
90  
91    @Override
92    public void incrementSucessfulGetRequests(int inc) {
93      sucGet.incr(inc);
94    }
95  
96    @Override
97    public void incrementSucessfulPutRequests(int inc) {
98      sucPut.incr(inc);
99    }
100 
101   @Override
102   public void incrementSucessfulDeleteRequests(int inc) {
103     sucDel.incr(inc);
104   }
105 
106   @Override
107   public void incrementFailedGetRequests(int inc) {
108     fGet.incr(inc);
109   }
110 
111   @Override
112   public void incrementFailedPutRequests(int inc) {
113     fPut.incr(inc);
114   }
115 
116   @Override
117   public void incrementFailedDeleteRequests(int inc) {
118     fDel.incr(inc);
119   }
120 
121   @Override
122   public void incrementSucessfulScanRequests(int inc) {
123     sucScan.incr(inc);
124   }
125 
126   @Override
127   public void incrementFailedScanRequests(int inc) {
128    fScan.incr(inc);
129   }
130 
131   @Override
132   public void incInfoThresholdExceeded(int count) {
133     infoPauseThresholdExceeded.incr(count);
134   }
135 
136   @Override
137   public void incWarnThresholdExceeded(int count) {
138     warnPauseThresholdExceeded.incr(count);
139   }
140 
141   @Override
142   public void updatePauseTimeWithGc(long t) {
143     pausesWithGc.add(t);
144   }
145 
146   @Override
147   public void updatePauseTimeWithoutGc(long t) {
148     pausesWithoutGc.add(t);
149   }
150 }