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 sucAppend;
41    private MutableFastCounter sucIncrement;
42    private MutableFastCounter fGet;
43    private MutableFastCounter fPut;
44    private MutableFastCounter fDel;
45    private MutableFastCounter fScan;
46    private MutableFastCounter fAppend;
47    private MutableFastCounter fIncrement;
48  
49    // pause monitor metrics
50    private final MutableFastCounter infoPauseThresholdExceeded;
51    private final MutableFastCounter warnPauseThresholdExceeded;
52    private final MetricHistogram pausesWithGc;
53    private final MetricHistogram pausesWithoutGc;
54  
55    public MetricsRESTSourceImpl() {
56      this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
57    }
58  
59    public MetricsRESTSourceImpl(String metricsName,
60                                 String metricsDescription,
61                                 String metricsContext,
62                                 String metricsJmxContext) {
63      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
64  
65      // pause monitor metrics
66      infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
67        INFO_THRESHOLD_COUNT_DESC, 0L);
68      warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
69        WARN_THRESHOLD_COUNT_DESC, 0L);
70      pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
71      pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
72    }
73  
74    @Override
75    public void init() {
76      super.init();
77      request = getMetricsRegistry().getCounter(REQUEST_KEY, 0l);
78  
79      sucGet = getMetricsRegistry().getCounter(SUCCESSFUL_GET_KEY, 0l);
80      sucPut = getMetricsRegistry().getCounter(SUCCESSFUL_PUT_KEY, 0l);
81      sucDel = getMetricsRegistry().getCounter(SUCCESSFUL_DELETE_KEY, 0l);
82      sucScan = getMetricsRegistry().getCounter(SUCCESSFUL_SCAN_KEY, 0L);
83      sucAppend = getMetricsRegistry().getCounter(SUCCESSFUL_APPEND_KEY, 0l);
84      sucIncrement = getMetricsRegistry().getCounter(SUCCESSFUL_INCREMENT_KEY, 0L);
85  
86      fGet = getMetricsRegistry().getCounter(FAILED_GET_KEY, 0l);
87      fPut = getMetricsRegistry().getCounter(FAILED_PUT_KEY, 0l);
88      fDel = getMetricsRegistry().getCounter(FAILED_DELETE_KEY, 0l);
89      fScan = getMetricsRegistry().getCounter(FAILED_SCAN_KEY, 0l);
90      fAppend = getMetricsRegistry().getCounter(FAILED_APPEND_KEY, 0l);
91      fIncrement = getMetricsRegistry().getCounter(FAILED_INCREMENT_KEY, 0L);
92    }
93  
94    @Override
95    public void incrementRequests(int inc) {
96      request.incr(inc);
97    }
98  
99    @Override
100   public void incrementSucessfulGetRequests(int inc) {
101     sucGet.incr(inc);
102   }
103 
104   @Override
105   public void incrementSucessfulPutRequests(int inc) {
106     sucPut.incr(inc);
107   }
108 
109   @Override
110   public void incrementSucessfulDeleteRequests(int inc) {
111     sucDel.incr(inc);
112   }
113 
114   @Override
115   public void incrementFailedGetRequests(int inc) {
116     fGet.incr(inc);
117   }
118 
119   @Override
120   public void incrementFailedPutRequests(int inc) {
121     fPut.incr(inc);
122   }
123 
124   @Override
125   public void incrementFailedDeleteRequests(int inc) {
126     fDel.incr(inc);
127   }
128 
129   @Override
130   public void incrementSucessfulScanRequests(int inc) {
131     sucScan.incr(inc);
132   }
133 
134   @Override
135   public void incrementFailedScanRequests(int inc) {
136    fScan.incr(inc);
137   }
138 
139   @Override
140   public void incrementSucessfulAppendRequests(int inc) {
141     sucAppend.incr(inc);
142   }
143 
144   @Override
145   public void incrementFailedAppendRequests(int inc) {
146     fAppend.incr(inc);
147   }
148 
149   @Override
150   public void incrementSucessfulIncrementRequests(int inc) {
151     sucIncrement.incr(inc);
152   }
153 
154   @Override
155   public void incrementFailedIncrementRequests(int inc) {
156     fIncrement.incr(inc);
157   }
158 
159   @Override
160   public void incInfoThresholdExceeded(int count) {
161     infoPauseThresholdExceeded.incr(count);
162   }
163 
164   @Override
165   public void incWarnThresholdExceeded(int count) {
166     warnPauseThresholdExceeded.incr(count);
167   }
168 
169   @Override
170   public void updatePauseTimeWithGc(long t) {
171     pausesWithGc.add(t);
172   }
173 
174   @Override
175   public void updatePauseTimeWithoutGc(long t) {
176     pausesWithoutGc.add(t);
177   }
178 }