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