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.MutableCounterLong;
23  
24  /**
25   * Hadoop Two 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 MutableCounterLong request;
33    private MutableCounterLong sucGet;
34    private MutableCounterLong sucPut;
35    private MutableCounterLong sucDel;
36    private MutableCounterLong fGet;
37    private MutableCounterLong fPut;
38    private MutableCounterLong fDel;
39  
40    public MetricsRESTSourceImpl() {
41      this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
42    }
43  
44    public MetricsRESTSourceImpl(String metricsName,
45                                 String metricsDescription,
46                                 String metricsContext,
47                                 String metricsJmxContext) {
48      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
49    }
50  
51    @Override
52    public void init() {
53      super.init();
54      request = getMetricsRegistry().getLongCounter(REQUEST_KEY, 0l);
55  
56      sucGet = getMetricsRegistry().getLongCounter(SUCCESSFUL_GET_KEY, 0l);
57      sucPut = getMetricsRegistry().getLongCounter(SUCCESSFUL_PUT_KEY, 0l);
58      sucDel = getMetricsRegistry().getLongCounter(SUCCESSFUL_DELETE_KEY, 0l);
59  
60      fGet = getMetricsRegistry().getLongCounter(FAILED_GET_KEY, 0l);
61      fPut = getMetricsRegistry().getLongCounter(FAILED_PUT_KEY, 0l);
62      fDel = getMetricsRegistry().getLongCounter(FAILED_DELETE_KEY, 0l);
63    }
64  
65    @Override
66    public void incrementRequests(int inc) {
67      request.incr(inc);
68    }
69  
70    @Override
71    public void incrementSucessfulGetRequests(int inc) {
72      sucGet.incr(inc);
73    }
74  
75    @Override
76    public void incrementSucessfulPutRequests(int inc) {
77      sucPut.incr(inc);
78    }
79  
80    @Override
81    public void incrementSucessfulDeleteRequests(int inc) {
82      sucDel.incr(inc);
83    }
84  
85    @Override
86    public void incrementFailedGetRequests(int inc) {
87      fGet.incr(inc);
88    }
89  
90    @Override
91    public void incrementFailedPutRequests(int inc) {
92      fPut.incr(inc);
93    }
94  
95    @Override
96    public void incrementFailedDeleteRequests(int inc) {
97      fDel.incr(inc);
98    }
99  }