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