1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
28
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
84 source.incCall(time);
85 if (time > slowResponseTime) {
86 source.incSlowCall(time);
87 }
88 }
89
90 }