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.lib.MetricMutableCounterLong;
23  
24  /**
25   * Hadoop One implementation of a metrics2 source that will export metrics from the Rest server to
26   * the hadoop metrics2 subsystem.
27   *
28   * Implements BaseSource through BaseSourceImpl, following the pattern
29   */
30  public class MetricsRESTSourceImpl extends BaseSourceImpl implements MetricsRESTSource {
31  
32    private MetricMutableCounterLong request;
33    private MetricMutableCounterLong sucGet;
34    private MetricMutableCounterLong sucPut;
35    private MetricMutableCounterLong sucDel;
36    private MetricMutableCounterLong sucScan;
37    private MetricMutableCounterLong fGet;
38    private MetricMutableCounterLong fPut;
39    private MetricMutableCounterLong fDel;
40    private MetricMutableCounterLong fScan;
41  
42    public MetricsRESTSourceImpl() {
43      this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
44    }
45  
46    public MetricsRESTSourceImpl(String metricsName,
47                                 String metricsDescription,
48                                 String metricsContext,
49                                 String metricsJmxContext) {
50      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
51    }
52  
53    @Override
54    public void init() {
55      super.init();
56      request = getMetricsRegistry().getLongCounter(REQUEST_KEY, 0l);
57  
58      sucGet = getMetricsRegistry().getLongCounter(SUCCESSFUL_GET_KEY, 0l);
59      sucPut = getMetricsRegistry().getLongCounter(SUCCESSFUL_PUT_KEY, 0l);
60      sucDel = getMetricsRegistry().getLongCounter(SUCCESSFUL_DELETE_KEY, 0l);
61      sucScan = getMetricsRegistry().getLongCounter(SUCCESSFUL_SCAN_KEY, 0L);
62  
63      fGet = getMetricsRegistry().getLongCounter(FAILED_GET_KEY, 0l);
64      fPut = getMetricsRegistry().getLongCounter(FAILED_PUT_KEY, 0l);
65      fDel = getMetricsRegistry().getLongCounter(FAILED_DELETE_KEY, 0l);
66      fScan = getMetricsRegistry().getLongCounter(FAILED_SCAN_KEY, 0l);
67    }
68  
69    @Override
70    public void incrementRequests(int inc) {
71      request.incr(inc);
72    }
73  
74    @Override
75    public void incrementSucessfulGetRequests(int inc) {
76      sucGet.incr(inc);
77    }
78  
79    @Override
80    public void incrementSucessfulPutRequests(int inc) {
81      sucPut.incr(inc);
82    }
83  
84    @Override
85    public void incrementSucessfulDeleteRequests(int inc) {
86      sucDel.incr(inc);
87    }
88  
89    @Override
90    public void incrementFailedGetRequests(int inc) {
91      fGet.incr(inc);
92    }
93  
94    @Override
95    public void incrementFailedPutRequests(int inc) {
96      fPut.incr(inc);
97    }
98  
99    @Override
100   public void incrementFailedDeleteRequests(int inc) {
101     fDel.incr(inc);
102   }
103 
104   @Override
105   public void incrementSucessfulScanRequests(int inc) {
106     sucScan.incr(inc);
107   }
108 
109   @Override
110   public void incrementFailedScanRequests(int inc) {
111     fScan.incr(inc);
112   }
113 }