View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.replication.regionserver;
19  
20  import org.apache.hadoop.hbase.metrics.MetricRegistryInfo;
21  import org.apache.hadoop.metrics2.lib.MutableFastCounter;
22  import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
23  import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
24  import org.apache.hadoop.metrics2.lib.MutableHistogram;
25  
26  public class MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource {
27  
28    private final MetricsReplicationSourceImpl rms;
29    private final String id;
30    private final String sizeOfLogQueueKey;
31    private final String ageOfLastShippedOpKey;
32    private final String logReadInEditsKey;
33    private final String logEditsFilteredKey;
34    private final String shippedBatchesKey;
35    private final String shippedOpsKey;
36    private String keyPrefix;
37  
38    @Deprecated
39    private final String shippedKBsKey;
40    private final String shippedBytesKey;
41    private final String logReadInBytesKey;
42    private final String shippedHFilesKey;
43    private final String sizeOfHFileRefsQueueKey;
44    private final String oldestWalAgeKey;
45    private final String sourceInitializingKey;
46  
47    private final MutableHistogram ageOfLastShippedOpHist;
48    private final MutableGaugeLong sizeOfLogQueueGauge;
49    private final MutableFastCounter logReadInEditsCounter;
50    private final MutableFastCounter logEditsFilteredCounter;
51    private final MutableFastCounter shippedBatchesCounter;
52    private final MutableFastCounter shippedOpsCounter;
53    private final MutableFastCounter shippedKBsCounter;
54    private final MutableFastCounter shippedBytesCounter;
55    private final MutableFastCounter logReadInBytesCounter;
56    private final MutableFastCounter shippedHFilesCounter;
57    private final MutableGaugeLong sizeOfHFileRefsQueueGauge;
58  
59    private final String unknownFileLengthKey;
60    private final String uncleanlyClosedKey;
61    private final String uncleanlySkippedBytesKey;
62    private final String restartedKey;
63    private final String repeatedBytesKey;
64    private final String completedLogsKey;
65    private final String completedRecoveryKey;
66    private final MutableFastCounter unknownFileLengthForClosedWAL;
67    private final MutableFastCounter uncleanlyClosedWAL;
68    private final MutableFastCounter uncleanlyClosedSkippedBytes;
69    private final MutableFastCounter restartWALReading;
70    private final MutableFastCounter repeatedFileBytes;
71    private final MutableFastCounter completedWAL;
72    private final MutableFastCounter completedRecoveryQueue;
73    private final MutableGaugeLong oldestWalAge;
74    private final MutableGaugeInt sourceInitializing;
75  
76    public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) {
77      this.rms = rms;
78      this.id = id;
79      this.keyPrefix = "source." + this.id + ".";
80  
81      ageOfLastShippedOpKey = this.keyPrefix + "ageOfLastShippedOp";
82      ageOfLastShippedOpHist = rms.getMetricsRegistry().getHistogram(ageOfLastShippedOpKey);
83  
84      sizeOfLogQueueKey = this.keyPrefix + "sizeOfLogQueue";
85      sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L);
86  
87      shippedBatchesKey = this.keyPrefix + "shippedBatches";
88      shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L);
89  
90      shippedOpsKey = this.keyPrefix + "shippedOps";
91      shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L);
92  
93      shippedKBsKey = this.keyPrefix + "shippedKBs";
94      shippedKBsCounter = rms.getMetricsRegistry().getCounter(shippedKBsKey, 0L);
95  
96      shippedBytesKey = this.keyPrefix + "shippedBytes";
97      shippedBytesCounter = rms.getMetricsRegistry().getCounter(shippedBytesKey, 0L);
98  
99      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     logEditsFilteredCounter = 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 public void setLastShippedAge(long age) {
143     ageOfLastShippedOpHist.add(age);
144   }
145 
146   @Override public void incrSizeOfLogQueue(int size) {
147     sizeOfLogQueueGauge.incr(size);
148   }
149 
150   @Override public void decrSizeOfLogQueue(int size) {
151     sizeOfLogQueueGauge.decr(size);
152   }
153 
154   @Override public void incrLogReadInEdits(long size) {
155     logReadInEditsCounter.incr(size);
156   }
157 
158   @Override public void incrLogEditsFiltered(long size) {
159     logEditsFilteredCounter.incr(size);
160   }
161 
162   @Override public void incrBatchesShipped(int batches) {
163     shippedBatchesCounter.incr(batches);
164   }
165 
166   @Override public void incrOpsShipped(long ops) {
167     shippedOpsCounter.incr(ops);
168   }
169 
170   @Override public void incrShippedBytes(long size) {
171     shippedBytesCounter.incr(size);
172     MetricsReplicationGlobalSourceSource
173       .incrementKBsCounter(shippedBytesCounter, shippedKBsCounter);
174   }
175 
176   @Override public void incrLogReadInBytes(long size) {
177     logReadInBytesCounter.incr(size);
178   }
179 
180   @Override public void clear() {
181     rms.removeMetric(ageOfLastShippedOpKey);
182 
183     rms.removeMetric(sizeOfLogQueueKey);
184 
185     rms.removeMetric(shippedBatchesKey);
186     rms.removeMetric(shippedOpsKey);
187     rms.removeMetric(shippedKBsKey);
188     rms.removeMetric(shippedBytesKey);
189 
190     rms.removeMetric(logReadInBytesKey);
191     rms.removeMetric(logReadInEditsKey);
192 
193     rms.removeMetric(logEditsFilteredKey);
194 
195     rms.removeMetric(shippedHFilesKey);
196     rms.removeMetric(sizeOfHFileRefsQueueKey);
197 
198     rms.removeMetric(unknownFileLengthKey);
199     rms.removeMetric(uncleanlyClosedKey);
200     rms.removeMetric(uncleanlySkippedBytesKey);
201     rms.removeMetric(restartedKey);
202     rms.removeMetric(repeatedBytesKey);
203     rms.removeMetric(completedLogsKey);
204     rms.removeMetric(completedRecoveryKey);
205     rms.removeMetric(oldestWalAgeKey);
206     rms.removeMetric(sourceInitializingKey);
207   }
208 
209   @Override
210   public long getLastShippedAge() {
211     return ageOfLastShippedOpHist.getMax();
212   }
213 
214   @Override
215   public void incrHFilesShipped(long hfiles) {
216     shippedHFilesCounter.incr(hfiles);
217   }
218 
219   @Override
220   public void incrSizeOfHFileRefsQueue(long size) {
221     sizeOfHFileRefsQueueGauge.incr(size);
222   }
223 
224   @Override
225   public void decrSizeOfHFileRefsQueue(long size) {
226     sizeOfHFileRefsQueueGauge.decr(size);
227   }
228 
229   @Override
230   public int getSizeOfLogQueue() {
231     return (int)sizeOfLogQueueGauge.value();
232   }
233 
234   @Override
235   public void incrUnknownFileLengthForClosedWAL() {
236     unknownFileLengthForClosedWAL.incr(1L);
237   }
238 
239   @Override
240   public void incrUncleanlyClosedWALs() {
241     uncleanlyClosedWAL.incr(1L);
242   }
243 
244   @Override
245   public long getUncleanlyClosedWALs() {
246     return uncleanlyClosedWAL.value();
247   }
248 
249   @Override
250   public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
251     uncleanlyClosedSkippedBytes.incr(bytes);
252   }
253 
254   @Override
255   public void incrRestartedWALReading() {
256     restartWALReading.incr(1L);
257   }
258 
259   @Override
260   public void incrRepeatedFileBytes(final long bytes) {
261     repeatedFileBytes.incr(bytes);
262   }
263 
264   @Override
265   public void incrCompletedWAL() {
266     completedWAL.incr(1L);
267   }
268 
269   @Override
270   public void incrCompletedRecoveryQueue() {
271     completedRecoveryQueue.incr(1L);
272   }
273 
274   @Override
275   public void incrFailedRecoveryQueue() {/*no op*/}
276 
277   @Override public void setOldestWalAge(long age) {
278     oldestWalAge.set(age);
279   }
280 
281   @Override public long getOldestWalAge() {
282     return oldestWalAge.value();
283   }
284 
285   @Override
286   public void incrSourceInitializing() {
287     sourceInitializing.incr(1);
288   }
289 
290   @Override
291   public int getSourceInitializing() {
292     return sourceInitializing.value();
293   }
294 
295   @Override public void decrSourceInitializing() {
296     sourceInitializing.decr(1);
297   }
298 
299   @Override
300   public void init() {
301     rms.init();
302   }
303 
304   @Override
305   public void setGauge(String gaugeName, long value) {
306     rms.setGauge(this.keyPrefix + gaugeName, value);
307   }
308 
309   @Override
310   public void incGauge(String gaugeName, long delta) {
311     rms.incGauge(this.keyPrefix + gaugeName, delta);
312   }
313 
314   @Override
315   public void decGauge(String gaugeName, long delta) {
316     rms.decGauge(this.keyPrefix + gaugeName, delta);
317   }
318 
319   @Override
320   public void removeMetric(String key) {
321     rms.removeMetric(this.keyPrefix + key);
322   }
323 
324   @Override
325   public void incCounters(String counterName, long delta) {
326     rms.incCounters(this.keyPrefix + counterName, delta);
327   }
328 
329   @Override
330   public void updateHistogram(String name, long value) {
331     rms.updateHistogram(this.keyPrefix + name, value);
332   }
333 
334   @Override
335   public String getMetricsContext() {
336     return rms.getMetricsContext();
337   }
338 
339   @Override
340   public String getMetricsDescription() {
341     return rms.getMetricsDescription();
342   }
343 
344   @Override
345   public String getMetricsJmxContext() {
346     return rms.getMetricsJmxContext();
347   }
348 
349   @Override
350   public String getMetricsName() {
351     return rms.getMetricsName();
352   }
353 
354   @Override
355   public MetricRegistryInfo getMetricRegistryInfo() {
356     return new MetricRegistryInfo(getMetricsName(), getMetricsDescription(),
357       getMetricsContext(), getMetricsJmxContext(), true);
358   }
359 }