1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client.metrics;
19
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.concurrent.atomic.AtomicLong;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.classification.InterfaceStability;
26
27 import com.google.common.collect.ImmutableMap;
28
29
30
31
32 @InterfaceAudience.Public
33 @InterfaceStability.Evolving
34 public class ServerSideScanMetrics {
35
36
37
38 private final Map<String, AtomicLong> counters = new HashMap<String, AtomicLong>();
39
40
41
42
43
44
45 protected AtomicLong createCounter(String counterName) {
46 AtomicLong c = new AtomicLong(0);
47 counters.put(counterName, c);
48 return c;
49 }
50
51 public static final String COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME = "ROWS_SCANNED";
52 public static final String COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME = "ROWS_FILTERED";
53
54
55 public static final String COUNT_OF_ROWS_SCANNED_KEY = COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME;
56
57 public static final String COUNT_OF_ROWS_FILTERED_KEY = COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME;
58
59
60
61
62 public final AtomicLong countOfRowsFiltered = createCounter(COUNT_OF_ROWS_FILTERED_KEY_METRIC_NAME);
63
64
65
66
67
68 public final AtomicLong countOfRowsScanned = createCounter(COUNT_OF_ROWS_SCANNED_KEY_METRIC_NAME);
69
70
71
72
73
74 public void setCounter(String counterName, long value) {
75 AtomicLong c = this.counters.get(counterName);
76 if (c != null) {
77 c.set(value);
78 }
79 }
80
81
82
83
84
85 public boolean hasCounter(String counterName) {
86 return this.counters.containsKey(counterName);
87 }
88
89
90
91
92
93 public AtomicLong getCounter(String counterName) {
94 return this.counters.get(counterName);
95 }
96
97
98
99
100
101 public void addToCounter(String counterName, long delta) {
102 AtomicLong c = this.counters.get(counterName);
103 if (c != null) {
104 c.addAndGet(delta);
105 }
106 }
107
108
109
110
111
112
113 public Map<String, Long> getMetricsMap() {
114
115 ImmutableMap.Builder<String, Long> builder = ImmutableMap.builder();
116
117 for (Map.Entry<String, AtomicLong> e : this.counters.entrySet()) {
118 builder.put(e.getKey(), e.getValue().getAndSet(0));
119 }
120
121 return builder.build();
122 }
123 }