View Javadoc

1   /*
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements. See the NOTICE file distributed with this
6    * work for additional information regarding copyright ownership. The ASF
7    * licenses this file to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16   * License for the specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.hadoop.hbase.thrift;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.conf.Configuration;
24  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
25  
26  /**
27   * This class is for maintaining the various statistics of thrift server
28   * and publishing them through the metrics interfaces.
29   */
30  @InterfaceAudience.Private
31  public class ThriftMetrics  {
32  
33  
34    public enum ThriftServerType {
35      ONE,
36      TWO
37    }
38  
39    public MetricsThriftServerSource getSource() {
40      return source;
41    }
42  
43    public void setSource(MetricsThriftServerSource source) {
44      this.source = source;
45    }
46  
47    private MetricsThriftServerSource source;
48    private final long slowResponseTime;
49    public static final String SLOW_RESPONSE_NANO_SEC =
50      "hbase.thrift.slow.response.nano.second";
51    public static final long DEFAULT_SLOW_RESPONSE_NANO_SEC = 10 * 1000 * 1000;
52  
53  
54    public ThriftMetrics(Configuration conf, ThriftServerType t) {
55      slowResponseTime = conf.getLong( SLOW_RESPONSE_NANO_SEC, DEFAULT_SLOW_RESPONSE_NANO_SEC);
56  
57      if (t == ThriftServerType.ONE) {
58        source = CompatibilitySingletonFactory.getInstance(MetricsThriftServerSourceFactory.class).createThriftOneSource();
59      } else if (t == ThriftServerType.TWO) {
60        source = CompatibilitySingletonFactory.getInstance(MetricsThriftServerSourceFactory.class).createThriftTwoSource();
61      }
62  
63    }
64  
65    public void incTimeInQueue(long time) {
66      source.incTimeInQueue(time);
67    }
68  
69    public void setCallQueueLen(int len) {
70      source.setCallQueueLen(len);
71    }
72  
73    public void incNumRowKeysInBatchGet(int diff) {
74      source.incNumRowKeysInBatchGet(diff);
75    }
76  
77    public void incNumRowKeysInBatchMutate(int diff) {
78      source.incNumRowKeysInBatchMutate(diff);
79    }
80  
81    public void incMethodTime(String name, long time) {
82      source.incMethodTime(name, time);
83      // inc general processTime
84      source.incCall(time);
85      if (time > slowResponseTime) {
86        source.incSlowCall(time);
87      }
88    }
89  
90  }