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.thrift;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
24  import org.apache.hadoop.metrics2.lib.MutableHistogram;
25  
26  /**
27   * Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource}
28   *
29   * Implements BaseSource through BaseSourceImpl, following the pattern
30   */
31  @InterfaceAudience.Private
32  public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
33      MetricsThriftServerSource {
34  
35    private MutableHistogram batchGetStat;
36    private MutableHistogram batchMutateStat;
37    private MutableHistogram queueTimeStat;
38  
39    private MutableHistogram thriftCallStat;
40    private MutableHistogram thriftSlowCallStat;
41  
42    private MutableGaugeLong callQueueLenGauge;
43  
44    public MetricsThriftServerSourceImpl(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      batchGetStat = getMetricsRegistry().newHistogram(BATCH_GET_KEY);
55      batchMutateStat = getMetricsRegistry().newHistogram(BATCH_MUTATE_KEY);
56      queueTimeStat = getMetricsRegistry().newHistogram(TIME_IN_QUEUE_KEY);
57      thriftCallStat = getMetricsRegistry().newHistogram(THRIFT_CALL_KEY);
58      thriftSlowCallStat = getMetricsRegistry().newHistogram(SLOW_THRIFT_CALL_KEY);
59      callQueueLenGauge = getMetricsRegistry().getLongGauge(CALL_QUEUE_LEN_KEY, 0);
60  
61    }
62  
63    @Override
64    public void incTimeInQueue(long time) {
65      queueTimeStat.add(time);
66    }
67  
68    @Override
69    public void setCallQueueLen(int len) {
70      callQueueLenGauge.set(len);
71    }
72  
73    @Override
74    public void incNumRowKeysInBatchGet(int diff) {
75      batchGetStat.add(diff);
76    }
77  
78    @Override
79    public void incNumRowKeysInBatchMutate(int diff) {
80      batchMutateStat.add(diff);
81    }
82  
83    @Override
84    public void incMethodTime(String name, long time) {
85      MutableHistogram s = getMetricsRegistry().getHistogram(name);
86      s.add(time);
87    }
88  
89    @Override
90    public void incCall(long time) {
91      thriftCallStat.add(time);
92    }
93  
94    @Override
95    public void incSlowCall(long time) {
96      thriftSlowCallStat.add(time);
97    }
98  
99  }