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