1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver.wal;
20
21 import java.util.concurrent.ConcurrentHashMap;
22 import java.util.concurrent.ConcurrentMap;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
26 import org.apache.hadoop.metrics2.MetricHistogram;
27 import org.apache.hadoop.metrics2.lib.MutableFastCounter;
28
29
30
31
32
33
34
35
36 @InterfaceAudience.Private
37 public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSource {
38
39 private final MetricHistogram appendSizeHisto;
40 private final MetricHistogram appendTimeHisto;
41 private final MetricHistogram syncTimeHisto;
42 private final MutableFastCounter appendCount;
43 private final MutableFastCounter slowAppendCount;
44 private final MutableFastCounter logRollRequested;
45 private final MutableFastCounter errorRollRequested;
46 private final MutableFastCounter lowReplicationRollRequested;
47 private final MutableFastCounter slowSyncRollRequested;
48 private final MutableFastCounter sizeRollRequested;
49 private final MutableFastCounter writtenBytes;
50 private final MutableFastCounter successfulLogRolls;
51
52 private final ConcurrentMap<TableName, MutableFastCounter> perTableAppendCount;
53 private final ConcurrentMap<TableName, MutableFastCounter> perTableAppendSize;
54
55 public MetricsWALSourceImpl() {
56 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT);
57 }
58
59 public MetricsWALSourceImpl(String metricsName,
60 String metricsDescription,
61 String metricsContext,
62 String metricsJmxContext) {
63 super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
64
65
66 appendTimeHisto = this.getMetricsRegistry().newTimeHistogram(APPEND_TIME, APPEND_TIME_DESC);
67 appendSizeHisto = this.getMetricsRegistry().newSizeHistogram(APPEND_SIZE, APPEND_SIZE_DESC);
68 appendCount = this.getMetricsRegistry().newCounter(APPEND_COUNT, APPEND_COUNT_DESC, 0l);
69 slowAppendCount =
70 this.getMetricsRegistry().newCounter(SLOW_APPEND_COUNT, SLOW_APPEND_COUNT_DESC, 0l);
71 syncTimeHisto = this.getMetricsRegistry().newTimeHistogram(SYNC_TIME, SYNC_TIME_DESC);
72 logRollRequested =
73 this.getMetricsRegistry().newCounter(ROLL_REQUESTED, ROLL_REQUESTED_DESC, 0L);
74 errorRollRequested = this.getMetricsRegistry()
75 .newCounter(ERROR_ROLL_REQUESTED, ERROR_ROLL_REQUESTED_DESC, 0L);
76 lowReplicationRollRequested = this.getMetricsRegistry()
77 .newCounter(LOW_REPLICA_ROLL_REQUESTED, LOW_REPLICA_ROLL_REQUESTED_DESC, 0L);
78 slowSyncRollRequested = this.getMetricsRegistry()
79 .newCounter(SLOW_SYNC_ROLL_REQUESTED, SLOW_SYNC_ROLL_REQUESTED_DESC, 0L);
80 sizeRollRequested = this.getMetricsRegistry()
81 .newCounter(SIZE_ROLL_REQUESTED, SIZE_ROLL_REQUESTED_DESC, 0L);
82 writtenBytes = this.getMetricsRegistry().newCounter(WRITTEN_BYTES, WRITTEN_BYTES_DESC, 0L);
83 successfulLogRolls = this.getMetricsRegistry()
84 .newCounter(SUCCESSFUL_LOG_ROLLS, SUCCESSFUL_LOG_ROLLS_DESC, 0L);
85 perTableAppendCount = new ConcurrentHashMap<>();
86 perTableAppendSize = new ConcurrentHashMap<>();
87 }
88
89 @Override
90 public void incrementAppendSize(TableName tableName, long size) {
91 appendSizeHisto.add(size);
92 MutableFastCounter tableAppendSizeCounter = perTableAppendSize.get(tableName);
93 if (tableAppendSizeCounter == null) {
94
95
96 String metricsKey = String.format("%s.%s", tableName, APPEND_SIZE);
97 perTableAppendSize.putIfAbsent(
98 tableName, getMetricsRegistry().newCounter(metricsKey, APPEND_SIZE_DESC, 0L));
99 tableAppendSizeCounter = perTableAppendSize.get(tableName);
100 }
101 tableAppendSizeCounter.incr(size);
102 }
103
104 @Override
105 public void incrementAppendTime(long time) {
106 appendTimeHisto.add(time);
107 }
108
109 @Override
110 public void incrementAppendCount(TableName tableName) {
111 appendCount.incr();
112 MutableFastCounter tableAppendCounter = perTableAppendCount.get(tableName);
113 if (tableAppendCounter == null) {
114 String metricsKey = String.format("%s.%s", tableName, APPEND_COUNT);
115 perTableAppendCount.putIfAbsent(
116 tableName, getMetricsRegistry().newCounter(metricsKey, APPEND_COUNT_DESC, 0L));
117 tableAppendCounter = perTableAppendCount.get(tableName);
118 }
119 tableAppendCounter.incr();
120 }
121
122 @Override
123 public void incrementSlowAppendCount() {
124 slowAppendCount.incr();
125 }
126
127 @Override
128 public void incrementSyncTime(long time) {
129 syncTimeHisto.add(time);
130 }
131
132 @Override
133 public void incrementLogRollRequested() {
134 logRollRequested.incr();
135 }
136
137 @Override
138 public void incrementErrorLogRoll() {
139 errorRollRequested.incr();
140 }
141
142 @Override
143 public void incrementLowReplicationLogRoll() {
144 lowReplicationRollRequested.incr();
145 }
146
147 @Override
148 public void incrementSlowSyncLogRoll() {
149 slowSyncRollRequested.incr();
150 }
151
152 @Override
153 public void incrementSizeLogRoll() {
154 sizeRollRequested.incr();
155 }
156
157 @Override
158 public void incrementWrittenBytes(long val) {
159 writtenBytes.incr(val);
160 }
161
162 @Override
163 public void incrementSuccessfulLogRolls() {
164 successfulLogRolls.incr();
165 }
166
167 @Override
168 public long getSuccessfulLogRolls() {
169 return successfulLogRolls.value();
170 }
171 }