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