001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.replication.regionserver; 019 020import org.apache.hadoop.metrics2.lib.MutableFastCounter; 021import org.apache.hadoop.metrics2.lib.MutableGaugeInt; 022import org.apache.hadoop.metrics2.lib.MutableGaugeLong; 023import org.apache.hadoop.metrics2.lib.MutableHistogram; 024import org.apache.yetus.audience.InterfaceAudience; 025 026@InterfaceAudience.Private 027public class MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource { 028 029 private final MetricsReplicationSourceImpl rms; 030 private final String id; 031 private final String sizeOfLogQueueKey; 032 private final String ageOfLastShippedOpKey; 033 private final String logReadInEditsKey; 034 private final String logEditsFilteredKey; 035 private final String shippedBatchesKey; 036 private final String shippedOpsKey; 037 private final String failedBatchesKey; 038 private String keyPrefix; 039 040 private final String shippedBytesKey; 041 private final String logReadInBytesKey; 042 private final String shippedHFilesKey; 043 private final String sizeOfHFileRefsQueueKey; 044 private final String oldestWalAgeKey; 045 private final String sourceInitializingKey; 046 047 private final MutableHistogram ageOfLastShippedOpHist; 048 private final MutableGaugeLong sizeOfLogQueueGauge; 049 private final MutableFastCounter logReadInEditsCounter; 050 private final MutableFastCounter walEditsFilteredCounter; 051 private final MutableFastCounter shippedBatchesCounter; 052 private final MutableFastCounter failedBatchesCounter; 053 private final MutableFastCounter shippedOpsCounter; 054 private final MutableFastCounter shippedBytesCounter; 055 private final MutableFastCounter logReadInBytesCounter; 056 private final MutableFastCounter shippedHFilesCounter; 057 private final MutableGaugeLong sizeOfHFileRefsQueueGauge; 058 059 private final String unknownFileLengthKey; 060 private final String uncleanlyClosedKey; 061 private final String uncleanlySkippedBytesKey; 062 private final String restartedKey; 063 private final String repeatedBytesKey; 064 private final String completedLogsKey; 065 private final String completedRecoveryKey; 066 private final MutableFastCounter unknownFileLengthForClosedWAL; 067 private final MutableFastCounter uncleanlyClosedWAL; 068 private final MutableFastCounter uncleanlyClosedSkippedBytes; 069 private final MutableFastCounter restartWALReading; 070 private final MutableFastCounter repeatedFileBytes; 071 private final MutableFastCounter completedWAL; 072 private final MutableFastCounter completedRecoveryQueue; 073 private final MutableGaugeLong oldestWalAge; 074 private final MutableGaugeInt sourceInitializing; 075 076 public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) { 077 this.rms = rms; 078 this.id = id; 079 this.keyPrefix = "source." + this.id + "."; 080 081 ageOfLastShippedOpKey = this.keyPrefix + "ageOfLastShippedOp"; 082 ageOfLastShippedOpHist = rms.getMetricsRegistry().newTimeHistogram(ageOfLastShippedOpKey); 083 084 sizeOfLogQueueKey = this.keyPrefix + "sizeOfLogQueue"; 085 sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L); 086 087 shippedBatchesKey = this.keyPrefix + "shippedBatches"; 088 shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L); 089 090 failedBatchesKey = this.keyPrefix + "failedBatches"; 091 failedBatchesCounter = rms.getMetricsRegistry().getCounter(failedBatchesKey, 0L); 092 093 shippedOpsKey = this.keyPrefix + "shippedOps"; 094 shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L); 095 096 shippedBytesKey = this.keyPrefix + "shippedBytes"; 097 shippedBytesCounter = rms.getMetricsRegistry().getCounter(shippedBytesKey, 0L); 098 099 logReadInBytesKey = this.keyPrefix + "logReadInBytes"; 100 logReadInBytesCounter = rms.getMetricsRegistry().getCounter(logReadInBytesKey, 0L); 101 102 logReadInEditsKey = this.keyPrefix + "logEditsRead"; 103 logReadInEditsCounter = rms.getMetricsRegistry().getCounter(logReadInEditsKey, 0L); 104 105 logEditsFilteredKey = this.keyPrefix + "logEditsFiltered"; 106 walEditsFilteredCounter = rms.getMetricsRegistry().getCounter(logEditsFilteredKey, 0L); 107 108 shippedHFilesKey = this.keyPrefix + "shippedHFiles"; 109 shippedHFilesCounter = rms.getMetricsRegistry().getCounter(shippedHFilesKey, 0L); 110 111 sizeOfHFileRefsQueueKey = this.keyPrefix + "sizeOfHFileRefsQueue"; 112 sizeOfHFileRefsQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfHFileRefsQueueKey, 0L); 113 114 unknownFileLengthKey = this.keyPrefix + "closedLogsWithUnknownFileLength"; 115 unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getCounter(unknownFileLengthKey, 0L); 116 117 uncleanlyClosedKey = this.keyPrefix + "uncleanlyClosedLogs"; 118 uncleanlyClosedWAL = rms.getMetricsRegistry().getCounter(uncleanlyClosedKey, 0L); 119 120 uncleanlySkippedBytesKey = this.keyPrefix + "ignoredUncleanlyClosedLogContentsInBytes"; 121 uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getCounter(uncleanlySkippedBytesKey, 0L); 122 123 restartedKey = this.keyPrefix + "restartedLogReading"; 124 restartWALReading = rms.getMetricsRegistry().getCounter(restartedKey, 0L); 125 126 repeatedBytesKey = this.keyPrefix + "repeatedLogFileBytes"; 127 repeatedFileBytes = rms.getMetricsRegistry().getCounter(repeatedBytesKey, 0L); 128 129 completedLogsKey = this.keyPrefix + "completedLogs"; 130 completedWAL = rms.getMetricsRegistry().getCounter(completedLogsKey, 0L); 131 132 completedRecoveryKey = this.keyPrefix + "completedRecoverQueues"; 133 completedRecoveryQueue = rms.getMetricsRegistry().getCounter(completedRecoveryKey, 0L); 134 135 oldestWalAgeKey = this.keyPrefix + "oldestWalAge"; 136 oldestWalAge = rms.getMetricsRegistry().getGauge(oldestWalAgeKey, 0L); 137 138 sourceInitializingKey = this.keyPrefix + "isInitializing"; 139 sourceInitializing = rms.getMetricsRegistry().getGaugeInt(sourceInitializingKey, 0); 140 } 141 142 @Override 143 public void setLastShippedAge(long age) { 144 ageOfLastShippedOpHist.add(age); 145 } 146 147 @Override 148 public void incrSizeOfLogQueue(int size) { 149 sizeOfLogQueueGauge.incr(size); 150 } 151 152 @Override 153 public void decrSizeOfLogQueue(int size) { 154 sizeOfLogQueueGauge.decr(size); 155 } 156 157 @Override 158 public void incrLogReadInEdits(long size) { 159 logReadInEditsCounter.incr(size); 160 } 161 162 @Override 163 public void incrLogEditsFiltered(long size) { 164 walEditsFilteredCounter.incr(size); 165 } 166 167 @Override 168 public void incrBatchesShipped(int batches) { 169 shippedBatchesCounter.incr(batches); 170 } 171 172 @Override 173 public void incrFailedBatches() { 174 failedBatchesCounter.incr(); 175 } 176 177 @Override 178 public void incrOpsShipped(long ops) { 179 shippedOpsCounter.incr(ops); 180 } 181 182 @Override 183 public void incrShippedBytes(long size) { 184 shippedBytesCounter.incr(size); 185 } 186 187 @Override 188 public void incrLogReadInBytes(long size) { 189 logReadInBytesCounter.incr(size); 190 } 191 192 @Override 193 public void clear() { 194 rms.removeMetric(ageOfLastShippedOpKey); 195 196 rms.removeMetric(sizeOfLogQueueKey); 197 198 rms.removeMetric(shippedBatchesKey); 199 rms.removeMetric(failedBatchesKey); 200 rms.removeMetric(shippedOpsKey); 201 rms.removeMetric(shippedBytesKey); 202 203 rms.removeMetric(logReadInBytesKey); 204 rms.removeMetric(logReadInEditsKey); 205 206 rms.removeMetric(logEditsFilteredKey); 207 208 rms.removeMetric(shippedHFilesKey); 209 rms.removeMetric(sizeOfHFileRefsQueueKey); 210 211 rms.removeMetric(unknownFileLengthKey); 212 rms.removeMetric(uncleanlyClosedKey); 213 rms.removeMetric(uncleanlySkippedBytesKey); 214 rms.removeMetric(restartedKey); 215 rms.removeMetric(repeatedBytesKey); 216 rms.removeMetric(completedLogsKey); 217 rms.removeMetric(completedRecoveryKey); 218 rms.removeMetric(oldestWalAgeKey); 219 rms.removeMetric(sourceInitializingKey); 220 } 221 222 @Override 223 public long getLastShippedAge() { 224 return ageOfLastShippedOpHist.getMax(); 225 } 226 227 @Override 228 public void incrHFilesShipped(long hfiles) { 229 shippedHFilesCounter.incr(hfiles); 230 } 231 232 @Override 233 public void incrSizeOfHFileRefsQueue(long size) { 234 sizeOfHFileRefsQueueGauge.incr(size); 235 } 236 237 @Override 238 public void decrSizeOfHFileRefsQueue(long size) { 239 sizeOfHFileRefsQueueGauge.decr(size); 240 } 241 242 @Override 243 public int getSizeOfLogQueue() { 244 return (int) sizeOfLogQueueGauge.value(); 245 } 246 247 @Override 248 public void incrUnknownFileLengthForClosedWAL() { 249 unknownFileLengthForClosedWAL.incr(1L); 250 } 251 252 @Override 253 public void incrUncleanlyClosedWALs() { 254 uncleanlyClosedWAL.incr(1L); 255 } 256 257 @Override 258 public long getUncleanlyClosedWALs() { 259 return uncleanlyClosedWAL.value(); 260 } 261 262 @Override 263 public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) { 264 uncleanlyClosedSkippedBytes.incr(bytes); 265 } 266 267 @Override 268 public void incrRestartedWALReading() { 269 restartWALReading.incr(1L); 270 } 271 272 @Override 273 public void incrRepeatedFileBytes(final long bytes) { 274 repeatedFileBytes.incr(bytes); 275 } 276 277 @Override 278 public void incrCompletedWAL() { 279 completedWAL.incr(1L); 280 } 281 282 @Override 283 public void incrCompletedRecoveryQueue() { 284 completedRecoveryQueue.incr(1L); 285 } 286 287 @Override 288 public void incrFailedRecoveryQueue() { 289 /* no op */} 290 291 @Override 292 public void setOldestWalAge(long age) { 293 oldestWalAge.set(age); 294 } 295 296 @Override 297 public long getOldestWalAge() { 298 return oldestWalAge.value(); 299 } 300 301 @Override 302 public void incrSourceInitializing() { 303 sourceInitializing.incr(1); 304 } 305 306 @Override 307 public int getSourceInitializing() { 308 return sourceInitializing.value(); 309 } 310 311 @Override 312 public void decrSourceInitializing() { 313 sourceInitializing.decr(1); 314 } 315 316 @Override 317 public void init() { 318 rms.init(); 319 } 320 321 @Override 322 public void setGauge(String gaugeName, long value) { 323 rms.setGauge(this.keyPrefix + gaugeName, value); 324 } 325 326 @Override 327 public void incGauge(String gaugeName, long delta) { 328 rms.incGauge(this.keyPrefix + gaugeName, delta); 329 } 330 331 @Override 332 public void decGauge(String gaugeName, long delta) { 333 rms.decGauge(this.keyPrefix + gaugeName, delta); 334 } 335 336 @Override 337 public void removeMetric(String key) { 338 rms.removeMetric(this.keyPrefix + key); 339 } 340 341 @Override 342 public void incCounters(String counterName, long delta) { 343 rms.incCounters(this.keyPrefix + counterName, delta); 344 } 345 346 @Override 347 public void updateHistogram(String name, long value) { 348 rms.updateHistogram(this.keyPrefix + name, value); 349 } 350 351 @Override 352 public String getMetricsContext() { 353 return rms.getMetricsContext(); 354 } 355 356 @Override 357 public String getMetricsDescription() { 358 return rms.getMetricsDescription(); 359 } 360 361 @Override 362 public String getMetricsJmxContext() { 363 return rms.getMetricsJmxContext(); 364 } 365 366 @Override 367 public String getMetricsName() { 368 return rms.getMetricsName(); 369 } 370 371 @Override 372 public long getWALEditsRead() { 373 return this.logReadInEditsCounter.value(); 374 } 375 376 @Override 377 public long getShippedOps() { 378 return this.shippedOpsCounter.value(); 379 } 380 381 @Override 382 public long getEditsFiltered() { 383 return this.walEditsFilteredCounter.value(); 384 } 385}