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.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
24  
25  /**
26   * Hadoop Two 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  @InterfaceAudience.Private
32  public class MetricsRESTSourceImpl extends BaseSourceImpl implements MetricsRESTSource {
33  
34    private MutableCounterLong request;
35    private MutableCounterLong sucGet;
36    private MutableCounterLong sucPut;
37    private MutableCounterLong sucDel;
38    private MutableCounterLong fGet;
39    private MutableCounterLong fPut;
40    private MutableCounterLong fDel;
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  
62      fGet = getMetricsRegistry().getLongCounter(FAILED_GET_KEY, 0l);
63      fPut = getMetricsRegistry().getLongCounter(FAILED_PUT_KEY, 0l);
64      fDel = getMetricsRegistry().getLongCounter(FAILED_DELETE_KEY, 0l);
65    }
66  
67    @Override
68    public void incrementRequests(int inc) {
69      request.incr(inc);
70    }
71  
72    @Override
73    public void incrementSucessfulGetRequests(int inc) {
74      sucGet.incr(inc);
75    }
76  
77    @Override
78    public void incrementSucessfulPutRequests(int inc) {
79      sucPut.incr(inc);
80    }
81  
82    @Override
83    public void incrementSucessfulDeleteRequests(int inc) {
84      sucDel.incr(inc);
85    }
86  
87    @Override
88    public void incrementFailedGetRequests(int inc) {
89      fGet.incr(inc);
90    }
91  
92    @Override
93    public void incrementFailedPutRequests(int inc) {
94      fPut.incr(inc);
95    }
96  
97    @Override
98    public void incrementFailedDeleteRequests(int inc) {
99      fDel.incr(inc);
100   }
101 }