1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.replication.regionserver;
19
20 import org.apache.hadoop.metrics2.lib.MutableFastCounter;
21 import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
22 import org.apache.hadoop.metrics2.lib.MutableHistogram;
23
24 public class MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource {
25
26 private final MetricsReplicationSourceImpl rms;
27 private final String id;
28 private final String keyPrefix;
29 private final String sizeOfLogQueueKey;
30 private final String ageOfLastShippedOpKey;
31 private final String logReadInEditsKey;
32 private final String logEditsFilteredKey;
33 private final String shippedBatchesKey;
34 private final String shippedOpsKey;
35 @Deprecated
36 private final String shippedKBsKey;
37 private final String shippedBytesKey;
38 private final String logReadInBytesKey;
39 private final String shippedHFilesKey;
40 private final String sizeOfHFileRefsQueueKey;
41
42 @Deprecated
43 private final MutableGaugeLong ageOfLastShippedOpGauge;
44 private final MutableHistogram ageOfLastShippedOpHist;
45 private final MutableGaugeLong sizeOfLogQueueGauge;
46 private final MutableFastCounter logReadInEditsCounter;
47 private final MutableFastCounter logEditsFilteredCounter;
48 private final MutableFastCounter shippedBatchesCounter;
49 private final MutableFastCounter shippedOpsCounter;
50 private final MutableFastCounter shippedKBsCounter;
51 private final MutableFastCounter shippedBytesCounter;
52 private final MutableFastCounter logReadInBytesCounter;
53 private final MutableFastCounter shippedHFilesCounter;
54 private final MutableGaugeLong sizeOfHFileRefsQueueGauge;
55
56 private final String unknownFileLengthKey;
57 private final String uncleanlyClosedKey;
58 private final String uncleanlySkippedBytesKey;
59 private final String restartedKey;
60 private final String repeatedBytesKey;
61 private final String completedLogsKey;
62 private final String completedRecoveryKey;
63 private final MutableFastCounter unknownFileLengthForClosedWAL;
64 private final MutableFastCounter uncleanlyClosedWAL;
65 private final MutableFastCounter uncleanlyClosedSkippedBytes;
66 private final MutableFastCounter restartWALReading;
67 private final MutableFastCounter repeatedFileBytes;
68 private final MutableFastCounter completedWAL;
69 private final MutableFastCounter completedRecoveryQueue;
70
71 public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) {
72 this.rms = rms;
73 this.id = id;
74 this.keyPrefix = "source." + this.id + ".";
75
76 ageOfLastShippedOpKey = "source." + id + ".ageOfLastShippedOp";
77 ageOfLastShippedOpHist = rms.getMetricsRegistry().getHistogram(ageOfLastShippedOpKey);
78 ageOfLastShippedOpGauge = rms.getMetricsRegistry()
79 .getCompatibilityRegistry().getGauge(ageOfLastShippedOpKey, 0L);
80
81 sizeOfLogQueueKey = "source." + id + ".sizeOfLogQueue";
82 sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L);
83
84 shippedBatchesKey = "source." + this.id + ".shippedBatches";
85 shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L);
86
87 shippedOpsKey = "source." + this.id + ".shippedOps";
88 shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L);
89
90 shippedKBsKey = "source." + this.id + ".shippedKBs";
91 shippedKBsCounter = rms.getMetricsRegistry().getCounter(shippedKBsKey, 0L);
92
93 shippedBytesKey = "source." + this.id + ".shippedBytes";
94 shippedBytesCounter = rms.getMetricsRegistry().getCounter(shippedBytesKey, 0L);
95
96 logReadInBytesKey = "source." + this.id + ".logReadInBytes";
97 logReadInBytesCounter = rms.getMetricsRegistry().getCounter(logReadInBytesKey, 0L);
98
99 logReadInEditsKey = "source." + id + ".logEditsRead";
100 logReadInEditsCounter = rms.getMetricsRegistry().getCounter(logReadInEditsKey, 0L);
101
102 logEditsFilteredKey = "source." + id + ".logEditsFiltered";
103 logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(logEditsFilteredKey, 0L);
104
105 shippedHFilesKey = "source." + this.id + ".shippedHFiles";
106 shippedHFilesCounter = rms.getMetricsRegistry().getCounter(shippedHFilesKey, 0L);
107
108 sizeOfHFileRefsQueueKey = "source." + id + ".sizeOfHFileRefsQueue";
109 sizeOfHFileRefsQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfHFileRefsQueueKey, 0L);
110
111 unknownFileLengthKey = this.keyPrefix + "closedLogsWithUnknownFileLength";
112 unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getCounter(unknownFileLengthKey, 0L);
113
114 uncleanlyClosedKey = this.keyPrefix + "uncleanlyClosedLogs";
115 uncleanlyClosedWAL = rms.getMetricsRegistry().getCounter(uncleanlyClosedKey, 0L);
116
117 uncleanlySkippedBytesKey = this.keyPrefix + "ignoredUncleanlyClosedLogContentsInBytes";
118 uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getCounter(uncleanlySkippedBytesKey, 0L);
119
120 restartedKey = this.keyPrefix + "restartedLogReading";
121 restartWALReading = rms.getMetricsRegistry().getCounter(restartedKey, 0L);
122
123 repeatedBytesKey = this.keyPrefix + "repeatedLogFileBytes";
124 repeatedFileBytes = rms.getMetricsRegistry().getCounter(repeatedBytesKey, 0L);
125
126 completedLogsKey = this.keyPrefix + "completedLogs";
127 completedWAL = rms.getMetricsRegistry().getCounter(completedLogsKey, 0L);
128
129 completedRecoveryKey = this.keyPrefix + "completedRecoverQueues";
130 completedRecoveryQueue = rms.getMetricsRegistry().getCounter(completedRecoveryKey, 0L);
131 }
132
133 @Override public void setLastShippedAge(long age) {
134 ageOfLastShippedOpHist.add(age);
135 ageOfLastShippedOpGauge.set(getLastShippedAge());
136 }
137
138 @Override public void incrSizeOfLogQueue(int size) {
139 sizeOfLogQueueGauge.incr(size);
140 }
141
142 @Override public void decrSizeOfLogQueue(int size) {
143 sizeOfLogQueueGauge.decr(size);
144 }
145
146 @Override public void incrLogReadInEdits(long size) {
147 logReadInEditsCounter.incr(size);
148 }
149
150 @Override public void incrLogEditsFiltered(long size) {
151 logEditsFilteredCounter.incr(size);
152 }
153
154 @Override public void incrBatchesShipped(int batches) {
155 shippedBatchesCounter.incr(batches);
156 }
157
158 @Override public void incrOpsShipped(long ops) {
159 shippedOpsCounter.incr(ops);
160 }
161
162 @Override public void incrShippedBytes(long size) {
163 shippedBytesCounter.incr(size);
164 MetricsReplicationGlobalSourceSource
165 .incrementKBsCounter(shippedBytesCounter, shippedKBsCounter);
166 }
167
168 @Override public void incrLogReadInBytes(long size) {
169 logReadInBytesCounter.incr(size);
170 }
171
172 @Override public void clear() {
173 rms.removeMetric(ageOfLastShippedOpKey);
174 rms.getMetricsRegistry().getCompatibilityRegistry().removeMetric(ageOfLastShippedOpKey);
175
176 rms.removeMetric(sizeOfLogQueueKey);
177
178 rms.removeMetric(shippedBatchesKey);
179 rms.removeMetric(shippedOpsKey);
180 rms.removeMetric(shippedKBsKey);
181 rms.removeMetric(shippedBytesKey);
182
183 rms.removeMetric(logReadInBytesKey);
184 rms.removeMetric(logReadInEditsKey);
185
186 rms.removeMetric(logEditsFilteredKey);
187
188 rms.removeMetric(shippedHFilesKey);
189 rms.removeMetric(sizeOfHFileRefsQueueKey);
190
191 rms.removeMetric(unknownFileLengthKey);
192 rms.removeMetric(uncleanlyClosedKey);
193 rms.removeMetric(uncleanlySkippedBytesKey);
194 rms.removeMetric(restartedKey);
195 rms.removeMetric(repeatedBytesKey);
196 rms.removeMetric(completedLogsKey);
197 rms.removeMetric(completedRecoveryKey);
198 }
199
200 @Override
201 public long getLastShippedAge() {
202 return ageOfLastShippedOpHist.getMax();
203 }
204
205 @Override
206 public void incrHFilesShipped(long hfiles) {
207 shippedHFilesCounter.incr(hfiles);
208 }
209
210 @Override
211 public void incrSizeOfHFileRefsQueue(long size) {
212 sizeOfHFileRefsQueueGauge.incr(size);
213 }
214
215 @Override
216 public void decrSizeOfHFileRefsQueue(long size) {
217 sizeOfHFileRefsQueueGauge.decr(size);
218 }
219
220 @Override
221 public int getSizeOfLogQueue() {
222 return (int)sizeOfLogQueueGauge.value();
223 }
224
225 @Override
226 public void incrUnknownFileLengthForClosedWAL() {
227 unknownFileLengthForClosedWAL.incr(1L);
228 }
229
230 @Override
231 public void incrUncleanlyClosedWALs() {
232 uncleanlyClosedWAL.incr(1L);
233 }
234
235 @Override
236 public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
237 uncleanlyClosedSkippedBytes.incr(bytes);
238 }
239
240 @Override
241 public void incrRestartedWALReading() {
242 restartWALReading.incr(1L);
243 }
244
245 @Override
246 public void incrRepeatedFileBytes(final long bytes) {
247 repeatedFileBytes.incr(bytes);
248 }
249
250 @Override
251 public void incrCompletedWAL() {
252 completedWAL.incr(1L);
253 }
254
255 @Override
256 public void incrCompletedRecoveryQueue() {
257 completedRecoveryQueue.incr(1L);
258 }
259
260 @Override
261 public void incrFailedRecoveryQueue() {
262
263 }
264 }