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.MutableGaugeLong; 022import org.apache.hadoop.metrics2.lib.MutableHistogram; 023import org.apache.yetus.audience.InterfaceAudience; 024 025@InterfaceAudience.Private 026public class MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource { 027 028 private final MetricsReplicationSourceImpl rms; 029 private final String id; 030 private final String sizeOfLogQueueKey; 031 private final String ageOfLastShippedOpKey; 032 private final String logReadInEditsKey; 033 private final String logEditsFilteredKey; 034 private final String shippedBatchesKey; 035 private final String shippedOpsKey; 036 private String keyPrefix; 037 038 /** 039 * @deprecated since 1.3.0. Use {@link #shippedBytesKey} instead. 040 */ 041 @Deprecated 042 private final String shippedKBsKey; 043 private final String shippedBytesKey; 044 private final String logReadInBytesKey; 045 private final String shippedHFilesKey; 046 private final String sizeOfHFileRefsQueueKey; 047 048 private final MutableHistogram ageOfLastShippedOpHist; 049 private final MutableGaugeLong sizeOfLogQueueGauge; 050 private final MutableFastCounter logReadInEditsCounter; 051 private final MutableFastCounter logEditsFilteredCounter; 052 private final MutableFastCounter shippedBatchesCounter; 053 private final MutableFastCounter shippedOpsCounter; 054 private final MutableFastCounter shippedKBsCounter; 055 private final MutableFastCounter shippedBytesCounter; 056 private final MutableFastCounter logReadInBytesCounter; 057 private final MutableFastCounter shippedHFilesCounter; 058 private final MutableGaugeLong sizeOfHFileRefsQueueGauge; 059 060 private final String unknownFileLengthKey; 061 private final String uncleanlyClosedKey; 062 private final String uncleanlySkippedBytesKey; 063 private final String restartedKey; 064 private final String repeatedBytesKey; 065 private final String completedLogsKey; 066 private final String completedRecoveryKey; 067 private final MutableFastCounter unknownFileLengthForClosedWAL; 068 private final MutableFastCounter uncleanlyClosedWAL; 069 private final MutableFastCounter uncleanlyClosedSkippedBytes; 070 private final MutableFastCounter restartWALReading; 071 private final MutableFastCounter repeatedFileBytes; 072 private final MutableFastCounter completedWAL; 073 private final MutableFastCounter completedRecoveryQueue; 074 075 public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) { 076 this.rms = rms; 077 this.id = id; 078 this.keyPrefix = "source." + this.id + "."; 079 080 ageOfLastShippedOpKey = this.keyPrefix + "ageOfLastShippedOp"; 081 ageOfLastShippedOpHist = rms.getMetricsRegistry().getHistogram(ageOfLastShippedOpKey); 082 083 sizeOfLogQueueKey = this.keyPrefix + "sizeOfLogQueue"; 084 sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L); 085 086 shippedBatchesKey = this.keyPrefix + "shippedBatches"; 087 shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L); 088 089 shippedOpsKey = this.keyPrefix + "shippedOps"; 090 shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L); 091 092 shippedKBsKey = this.keyPrefix + "shippedKBs"; 093 shippedKBsCounter = rms.getMetricsRegistry().getCounter(shippedKBsKey, 0L); 094 095 shippedBytesKey = this.keyPrefix + "shippedBytes"; 096 shippedBytesCounter = rms.getMetricsRegistry().getCounter(shippedBytesKey, 0L); 097 098 logReadInBytesKey = this.keyPrefix + "logReadInBytes"; 099 logReadInBytesCounter = rms.getMetricsRegistry().getCounter(logReadInBytesKey, 0L); 100 101 logReadInEditsKey = this.keyPrefix + "logEditsRead"; 102 logReadInEditsCounter = rms.getMetricsRegistry().getCounter(logReadInEditsKey, 0L); 103 104 logEditsFilteredKey = this.keyPrefix + "logEditsFiltered"; 105 logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(logEditsFilteredKey, 0L); 106 107 shippedHFilesKey = this.keyPrefix + "shippedHFiles"; 108 shippedHFilesCounter = rms.getMetricsRegistry().getCounter(shippedHFilesKey, 0L); 109 110 sizeOfHFileRefsQueueKey = this.keyPrefix + "sizeOfHFileRefsQueue"; 111 sizeOfHFileRefsQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfHFileRefsQueueKey, 0L); 112 113 unknownFileLengthKey = this.keyPrefix + "closedLogsWithUnknownFileLength"; 114 unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getCounter(unknownFileLengthKey, 0L); 115 116 uncleanlyClosedKey = this.keyPrefix + "uncleanlyClosedLogs"; 117 uncleanlyClosedWAL = rms.getMetricsRegistry().getCounter(uncleanlyClosedKey, 0L); 118 119 uncleanlySkippedBytesKey = this.keyPrefix + "ignoredUncleanlyClosedLogContentsInBytes"; 120 uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getCounter(uncleanlySkippedBytesKey, 0L); 121 122 restartedKey = this.keyPrefix + "restartedLogReading"; 123 restartWALReading = rms.getMetricsRegistry().getCounter(restartedKey, 0L); 124 125 repeatedBytesKey = this.keyPrefix + "repeatedLogFileBytes"; 126 repeatedFileBytes = rms.getMetricsRegistry().getCounter(repeatedBytesKey, 0L); 127 128 completedLogsKey = this.keyPrefix + "completedLogs"; 129 completedWAL = rms.getMetricsRegistry().getCounter(completedLogsKey, 0L); 130 131 completedRecoveryKey = this.keyPrefix + "completedRecoverQueues"; 132 completedRecoveryQueue = rms.getMetricsRegistry().getCounter(completedRecoveryKey, 0L); 133 } 134 135 @Override public void setLastShippedAge(long age) { 136 ageOfLastShippedOpHist.add(age); 137 } 138 139 @Override public void incrSizeOfLogQueue(int size) { 140 sizeOfLogQueueGauge.incr(size); 141 } 142 143 @Override public void decrSizeOfLogQueue(int size) { 144 sizeOfLogQueueGauge.decr(size); 145 } 146 147 @Override public void incrLogReadInEdits(long size) { 148 logReadInEditsCounter.incr(size); 149 } 150 151 @Override public void incrLogEditsFiltered(long size) { 152 logEditsFilteredCounter.incr(size); 153 } 154 155 @Override public void incrBatchesShipped(int batches) { 156 shippedBatchesCounter.incr(batches); 157 } 158 159 @Override public void incrOpsShipped(long ops) { 160 shippedOpsCounter.incr(ops); 161 } 162 163 @Override public void incrShippedBytes(long size) { 164 shippedBytesCounter.incr(size); 165 MetricsReplicationGlobalSourceSource 166 .incrementKBsCounter(shippedBytesCounter, shippedKBsCounter); 167 } 168 169 @Override public void incrLogReadInBytes(long size) { 170 logReadInBytesCounter.incr(size); 171 } 172 173 @Override public void clear() { 174 rms.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 init() { 262 rms.init(); 263 } 264 265 @Override 266 public void setGauge(String gaugeName, long value) { 267 rms.setGauge(this.keyPrefix + gaugeName, value); 268 } 269 270 @Override 271 public void incGauge(String gaugeName, long delta) { 272 rms.incGauge(this.keyPrefix + gaugeName, delta); 273 } 274 275 @Override 276 public void decGauge(String gaugeName, long delta) { 277 rms.decGauge(this.keyPrefix + gaugeName, delta); 278 } 279 280 @Override 281 public void removeMetric(String key) { 282 rms.removeMetric(this.keyPrefix + key); 283 } 284 285 @Override 286 public void incCounters(String counterName, long delta) { 287 rms.incCounters(this.keyPrefix + counterName, delta); 288 } 289 290 @Override 291 public void updateHistogram(String name, long value) { 292 rms.updateHistogram(this.keyPrefix + name, value); 293 } 294 295 @Override 296 public String getMetricsContext() { 297 return rms.getMetricsContext(); 298 } 299 300 @Override 301 public String getMetricsDescription() { 302 return rms.getMetricsDescription(); 303 } 304 305 @Override 306 public String getMetricsJmxContext() { 307 return rms.getMetricsJmxContext(); 308 } 309 310 @Override 311 public String getMetricsName() { 312 return rms.getMetricsName(); 313 } 314}