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.MetricMutableCounterLong;
23  import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
24  import org.apache.hadoop.metrics2.lib.MetricMutableHistogram;
25  import org.apache.hadoop.metrics2.lib.MetricMutableStat;
26  
27  /**
28   * Hadoop 1 version of MetricsThriftServerSource{@link MetricsThriftServerSource}
29   *
30   * Implements BaseSource through BaseSourceImpl, following the pattern
31   */
32  public class MetricsThriftServerSourceImpl extends BaseSourceImpl implements
33      MetricsThriftServerSource {
34  
35  
36    private MetricMutableHistogram batchGetStat;
37    private MetricMutableHistogram batchMutateStat;
38    private MetricMutableHistogram queueTimeStat;
39  
40    private MetricMutableHistogram thriftCallStat;
41    private MetricMutableHistogram thriftSlowCallStat;
42  
43    private MetricMutableGaugeLong callQueueLenGauge;
44  
45    // pause monitor metrics
46    private final MetricMutableCounterLong infoPauseThresholdExceeded;
47    private final MetricMutableCounterLong warnPauseThresholdExceeded;
48    private final MetricMutableHistogram pausesWithGc;
49    private final MetricMutableHistogram pausesWithoutGc;
50  
51    public MetricsThriftServerSourceImpl(String metricsName,
52                                         String metricsDescription,
53                                         String metricsContext,
54                                         String metricsJmxContext) {
55      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
56  
57      // pause monitor metrics
58      infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
59        INFO_THRESHOLD_COUNT_DESC, 0L);
60      warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
61        WARN_THRESHOLD_COUNT_DESC, 0L);
62      pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
63      pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
64    }
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().getLongGauge(CALL_QUEUE_LEN_KEY, 0);
76    }
77  
78    @Override
79    public void incTimeInQueue(long time) {
80      queueTimeStat.add(time);
81    }
82  
83    @Override
84    public void setCallQueueLen(int len) {
85      callQueueLenGauge.set(len);
86    }
87  
88    @Override
89    public void incNumRowKeysInBatchGet(int diff) {
90      batchGetStat.add(diff);
91    }
92  
93    @Override
94    public void incNumRowKeysInBatchMutate(int diff) {
95      batchMutateStat.add(diff);
96    }
97  
98    @Override
99    public void incMethodTime(String name, long time) {
100     MetricMutableHistogram s = getMetricsRegistry().getHistogram(name);
101     s.add(time);
102   }
103 
104   @Override
105   public void incCall(long time) {
106     thriftCallStat.add(time);
107   }
108 
109   @Override
110   public void incSlowCall(long time) {
111     thriftSlowCallStat.add(time);
112   }
113 
114   @Override
115   public void incInfoThresholdExceeded(int count) {
116     infoPauseThresholdExceeded.incr(count);
117   }
118 
119   @Override
120   public void incWarnThresholdExceeded(int count) {
121     warnPauseThresholdExceeded.incr(count);
122   }
123 
124   @Override
125   public void updatePauseTimeWithGc(long t) {
126     pausesWithGc.add(t);
127   }
128 
129   @Override
130   public void updatePauseTimeWithoutGc(long t) {
131     pausesWithoutGc.add(t);
132   }
133 }