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.MutableFastCounter;
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 BaseSourceImpl 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    // pause monitor metrics
47    private final MutableFastCounter infoPauseThresholdExceeded;
48    private final MutableFastCounter warnPauseThresholdExceeded;
49    private final MetricHistogram pausesWithGc;
50    private final MetricHistogram pausesWithoutGc;
51  
52    public MetricsThriftServerSourceImpl(String metricsName,
53                                         String metricsDescription,
54                                         String metricsContext,
55                                         String metricsJmxContext) {
56      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
57  
58      // pause monitor metrics
59      infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
60        INFO_THRESHOLD_COUNT_DESC, 0L);
61      warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
62        WARN_THRESHOLD_COUNT_DESC, 0L);
63      pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
64      pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
65    }
66  
67    @Override
68    public void init() {
69      super.init();
70      batchGetStat = getMetricsRegistry().newTimeHistogram(BATCH_GET_KEY);
71      batchMutateStat = getMetricsRegistry().newTimeHistogram(BATCH_MUTATE_KEY);
72      queueTimeStat = getMetricsRegistry().newTimeHistogram(TIME_IN_QUEUE_KEY);
73      thriftCallStat = getMetricsRegistry().newTimeHistogram(THRIFT_CALL_KEY);
74      thriftSlowCallStat = getMetricsRegistry().newTimeHistogram(SLOW_THRIFT_CALL_KEY);
75      callQueueLenGauge = getMetricsRegistry().getGauge(CALL_QUEUE_LEN_KEY, 0);
76  
77    }
78  
79    @Override
80    public void incTimeInQueue(long time) {
81      queueTimeStat.add(time);
82    }
83  
84    @Override
85    public void setCallQueueLen(int len) {
86      callQueueLenGauge.set(len);
87    }
88  
89    @Override
90    public void incNumRowKeysInBatchGet(int diff) {
91      batchGetStat.add(diff);
92    }
93  
94    @Override
95    public void incNumRowKeysInBatchMutate(int diff) {
96      batchMutateStat.add(diff);
97    }
98  
99    @Override
100   public void incMethodTime(String name, long time) {
101     MutableHistogram s = getMetricsRegistry().getHistogram(name);
102     s.add(time);
103   }
104 
105   @Override
106   public void incCall(long time) {
107     thriftCallStat.add(time);
108   }
109 
110   @Override
111   public void incSlowCall(long time) {
112     thriftSlowCallStat.add(time);
113   }
114 
115   @Override
116   public void incInfoThresholdExceeded(int count) {
117     infoPauseThresholdExceeded.incr(count);
118   }
119 
120   @Override
121   public void incWarnThresholdExceeded(int count) {
122     warnPauseThresholdExceeded.incr(count);
123   }
124 
125   @Override
126   public void updatePauseTimeWithGc(long t) {
127     pausesWithGc.add(t);
128   }
129 
130   @Override
131   public void updatePauseTimeWithoutGc(long t) {
132     pausesWithoutGc.add(t);
133   }
134 }