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.MutableFastCounter;
26  import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
27  import org.apache.hadoop.metrics2.lib.MutableHistogram;
28  
29  /**
30   * Hadoop 2 version of MetricsThriftServerSource{@link org.apache.hadoop.hbase.thrift.MetricsThriftServerSource}
31   *
32   * Implements BaseSource through BaseSourceImpl, following the pattern
33   */
34  @InterfaceAudience.Private
35  public class MetricsThriftServerSourceImpl extends ExceptionTrackingSourceImpl implements
36      MetricsThriftServerSource {
37  
38    private MetricHistogram batchGetStat;
39    private MetricHistogram batchMutateStat;
40    private MetricHistogram queueTimeStat;
41  
42    private MetricHistogram thriftCallStat;
43    private MetricHistogram thriftSlowCallStat;
44  
45    private MutableGaugeLong callQueueLenGauge;
46  
47    // pause monitor metrics
48    private final MutableFastCounter infoPauseThresholdExceeded;
49    private final MutableFastCounter warnPauseThresholdExceeded;
50    private final MetricHistogram pausesWithGc;
51    private final MetricHistogram pausesWithoutGc;
52  
53    private MutableGaugeLong activeWorkerCountGauge;
54  
55    public MetricsThriftServerSourceImpl(String metricsName,
56                                         String metricsDescription,
57                                         String metricsContext,
58                                         String metricsJmxContext) {
59      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
60  
61      // pause monitor metrics
62      infoPauseThresholdExceeded = getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY,
63        INFO_THRESHOLD_COUNT_DESC, 0L);
64      warnPauseThresholdExceeded = getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY,
65        WARN_THRESHOLD_COUNT_DESC, 0L);
66      pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
67      pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
68    }
69  
70    @Override
71    public void init() {
72      super.init();
73      batchGetStat = getMetricsRegistry().newTimeHistogram(BATCH_GET_KEY);
74      batchMutateStat = getMetricsRegistry().newTimeHistogram(BATCH_MUTATE_KEY);
75      queueTimeStat = getMetricsRegistry().newTimeHistogram(TIME_IN_QUEUE_KEY);
76      thriftCallStat = getMetricsRegistry().newTimeHistogram(THRIFT_CALL_KEY);
77      thriftSlowCallStat = getMetricsRegistry().newTimeHistogram(SLOW_THRIFT_CALL_KEY);
78      callQueueLenGauge = getMetricsRegistry().getGauge(CALL_QUEUE_LEN_KEY, 0);
79      activeWorkerCountGauge = getMetricsRegistry().getGauge(ACTIVE_WORKER_COUNT_KEY, 0);
80    }
81  
82    @Override
83    public void incTimeInQueue(long time) {
84      queueTimeStat.add(time);
85    }
86  
87    @Override
88    public void setCallQueueLen(int len) {
89      callQueueLenGauge.set(len);
90    }
91  
92    @Override
93    public void incNumRowKeysInBatchGet(int diff) {
94      batchGetStat.add(diff);
95    }
96  
97    @Override
98    public void incNumRowKeysInBatchMutate(int diff) {
99      batchMutateStat.add(diff);
100   }
101 
102   @Override
103   public void incMethodTime(String name, long time) {
104     MutableHistogram s = getMetricsRegistry().getHistogram(name);
105     s.add(time);
106   }
107 
108   @Override
109   public void incCall(long time) {
110     thriftCallStat.add(time);
111   }
112 
113   @Override
114   public void incSlowCall(long time) {
115     thriftSlowCallStat.add(time);
116   }
117 
118   public void incActiveWorkerCount() {
119     activeWorkerCountGauge.incr();
120   }
121 
122   @Override
123   public void decActiveWorkerCount() {
124     activeWorkerCountGauge.decr();
125   }
126 
127   @Override
128   public void incInfoThresholdExceeded(int count) {
129     infoPauseThresholdExceeded.incr(count);
130   }
131 
132   @Override
133   public void incWarnThresholdExceeded(int count) {
134     warnPauseThresholdExceeded.incr(count);
135   }
136 
137   @Override
138   public void updatePauseTimeWithGc(long t) {
139     pausesWithGc.add(t);
140   }
141 
142   @Override
143   public void updatePauseTimeWithoutGc(long t) {
144     pausesWithoutGc.add(t);
145   }
146 }