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 sucScan;
39    private MutableCounterLong fGet;
40    private MutableCounterLong fPut;
41    private MutableCounterLong fDel;
42    private MutableCounterLong fScan;
43  
44    public MetricsRESTSourceImpl() {
45      this(METRICS_NAME, METRICS_DESCRIPTION, CONTEXT, JMX_CONTEXT);
46    }
47  
48    public MetricsRESTSourceImpl(String metricsName,
49                                 String metricsDescription,
50                                 String metricsContext,
51                                 String metricsJmxContext) {
52      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
53    }
54  
55    @Override
56    public void init() {
57      super.init();
58      request = getMetricsRegistry().getLongCounter(REQUEST_KEY, 0l);
59  
60      sucGet = getMetricsRegistry().getLongCounter(SUCCESSFUL_GET_KEY, 0l);
61      sucPut = getMetricsRegistry().getLongCounter(SUCCESSFUL_PUT_KEY, 0l);
62      sucDel = getMetricsRegistry().getLongCounter(SUCCESSFUL_DELETE_KEY, 0l);
63      sucScan = getMetricsRegistry().getLongCounter(SUCCESSFUL_SCAN_KEY, 0L);
64  
65      fGet = getMetricsRegistry().getLongCounter(FAILED_GET_KEY, 0l);
66      fPut = getMetricsRegistry().getLongCounter(FAILED_PUT_KEY, 0l);
67      fDel = getMetricsRegistry().getLongCounter(FAILED_DELETE_KEY, 0l);
68      fScan = getMetricsRegistry().getLongCounter(FAILED_SCAN_KEY, 0l);
69    }
70  
71    @Override
72    public void incrementRequests(int inc) {
73      request.incr(inc);
74    }
75  
76    @Override
77    public void incrementSucessfulGetRequests(int inc) {
78      sucGet.incr(inc);
79    }
80  
81    @Override
82    public void incrementSucessfulPutRequests(int inc) {
83      sucPut.incr(inc);
84    }
85  
86    @Override
87    public void incrementSucessfulDeleteRequests(int inc) {
88      sucDel.incr(inc);
89    }
90  
91    @Override
92    public void incrementFailedGetRequests(int inc) {
93      fGet.incr(inc);
94    }
95  
96    @Override
97    public void incrementFailedPutRequests(int inc) {
98      fPut.incr(inc);
99    }
100 
101   @Override
102   public void incrementFailedDeleteRequests(int inc) {
103     fDel.incr(inc);
104   }
105 
106   @Override
107   public void incrementSucessfulScanRequests(int inc) {
108     sucScan.incr(inc);
109   }
110 
111   @Override
112   public void incrementFailedScanRequests(int inc) {
113    fScan.incr(inc);
114   }
115 }