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.MutableGaugeLong;
23  import org.apache.hadoop.metrics2.lib.MutableHistogram;
24  
25  public class MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource {
26  
27    private final MetricsReplicationSourceImpl rms;
28    private final String id;
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    private String keyPrefix;
36  
37    @Deprecated
38    private final String shippedKBsKey;
39    private final String shippedBytesKey;
40    private final String logReadInBytesKey;
41    private final String shippedHFilesKey;
42    private final String sizeOfHFileRefsQueueKey;
43  
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 = this.keyPrefix + "ageOfLastShippedOp";
77      ageOfLastShippedOpHist = rms.getMetricsRegistry().getHistogram(ageOfLastShippedOpKey);
78  
79      sizeOfLogQueueKey = this.keyPrefix + "sizeOfLogQueue";
80      sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L);
81  
82      shippedBatchesKey = this.keyPrefix + "shippedBatches";
83      shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L);
84  
85      shippedOpsKey = this.keyPrefix + "shippedOps";
86      shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L);
87  
88      shippedKBsKey = this.keyPrefix + "shippedKBs";
89      shippedKBsCounter = rms.getMetricsRegistry().getCounter(shippedKBsKey, 0L);
90  
91      shippedBytesKey = this.keyPrefix + "shippedBytes";
92      shippedBytesCounter = rms.getMetricsRegistry().getCounter(shippedBytesKey, 0L);
93  
94      logReadInBytesKey = this.keyPrefix + "logReadInBytes";
95      logReadInBytesCounter = rms.getMetricsRegistry().getCounter(logReadInBytesKey, 0L);
96  
97      logReadInEditsKey = this.keyPrefix + "logEditsRead";
98      logReadInEditsCounter = rms.getMetricsRegistry().getCounter(logReadInEditsKey, 0L);
99  
100     logEditsFilteredKey = this.keyPrefix + "logEditsFiltered";
101     logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(logEditsFilteredKey, 0L);
102 
103     shippedHFilesKey = this.keyPrefix + "shippedHFiles";
104     shippedHFilesCounter = rms.getMetricsRegistry().getCounter(shippedHFilesKey, 0L);
105 
106     sizeOfHFileRefsQueueKey = this.keyPrefix + "sizeOfHFileRefsQueue";
107     sizeOfHFileRefsQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfHFileRefsQueueKey, 0L);
108 
109     unknownFileLengthKey = this.keyPrefix + "closedLogsWithUnknownFileLength";
110     unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getCounter(unknownFileLengthKey, 0L);
111 
112     uncleanlyClosedKey = this.keyPrefix + "uncleanlyClosedLogs";
113     uncleanlyClosedWAL = rms.getMetricsRegistry().getCounter(uncleanlyClosedKey, 0L);
114 
115     uncleanlySkippedBytesKey = this.keyPrefix + "ignoredUncleanlyClosedLogContentsInBytes";
116     uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getCounter(uncleanlySkippedBytesKey, 0L);
117 
118     restartedKey = this.keyPrefix + "restartedLogReading";
119     restartWALReading = rms.getMetricsRegistry().getCounter(restartedKey, 0L);
120 
121     repeatedBytesKey = this.keyPrefix + "repeatedLogFileBytes";
122     repeatedFileBytes = rms.getMetricsRegistry().getCounter(repeatedBytesKey, 0L);
123 
124     completedLogsKey = this.keyPrefix + "completedLogs";
125     completedWAL = rms.getMetricsRegistry().getCounter(completedLogsKey, 0L);
126 
127     completedRecoveryKey = this.keyPrefix + "completedRecoverQueues";
128     completedRecoveryQueue = rms.getMetricsRegistry().getCounter(completedRecoveryKey, 0L);
129   }
130 
131   @Override public void setLastShippedAge(long age) {
132     ageOfLastShippedOpHist.add(age);
133   }
134 
135   @Override public void incrSizeOfLogQueue(int size) {
136     sizeOfLogQueueGauge.incr(size);
137   }
138 
139   @Override public void decrSizeOfLogQueue(int size) {
140     sizeOfLogQueueGauge.decr(size);
141   }
142 
143   @Override public void incrLogReadInEdits(long size) {
144     logReadInEditsCounter.incr(size);
145   }
146 
147   @Override public void incrLogEditsFiltered(long size) {
148     logEditsFilteredCounter.incr(size);
149   }
150 
151   @Override public void incrBatchesShipped(int batches) {
152     shippedBatchesCounter.incr(batches);
153   }
154 
155   @Override public void incrOpsShipped(long ops) {
156     shippedOpsCounter.incr(ops);
157   }
158 
159   @Override public void incrShippedBytes(long size) {
160     shippedBytesCounter.incr(size);
161     MetricsReplicationGlobalSourceSource
162       .incrementKBsCounter(shippedBytesCounter, shippedKBsCounter);
163   }
164 
165   @Override public void incrLogReadInBytes(long size) {
166     logReadInBytesCounter.incr(size);
167   }
168 
169   @Override public void clear() {
170     rms.removeMetric(ageOfLastShippedOpKey);
171 
172     rms.removeMetric(sizeOfLogQueueKey);
173 
174     rms.removeMetric(shippedBatchesKey);
175     rms.removeMetric(shippedOpsKey);
176     rms.removeMetric(shippedKBsKey);
177     rms.removeMetric(shippedBytesKey);
178 
179     rms.removeMetric(logReadInBytesKey);
180     rms.removeMetric(logReadInEditsKey);
181 
182     rms.removeMetric(logEditsFilteredKey);
183 
184     rms.removeMetric(shippedHFilesKey);
185     rms.removeMetric(sizeOfHFileRefsQueueKey);
186 
187     rms.removeMetric(unknownFileLengthKey);
188     rms.removeMetric(uncleanlyClosedKey);
189     rms.removeMetric(uncleanlySkippedBytesKey);
190     rms.removeMetric(restartedKey);
191     rms.removeMetric(repeatedBytesKey);
192     rms.removeMetric(completedLogsKey);
193     rms.removeMetric(completedRecoveryKey);
194   }
195 
196   @Override
197   public long getLastShippedAge() {
198     return ageOfLastShippedOpHist.getMax();
199   }
200 
201   @Override
202   public void incrHFilesShipped(long hfiles) {
203     shippedHFilesCounter.incr(hfiles);
204   }
205 
206   @Override
207   public void incrSizeOfHFileRefsQueue(long size) {
208     sizeOfHFileRefsQueueGauge.incr(size);
209   }
210 
211   @Override
212   public void decrSizeOfHFileRefsQueue(long size) {
213     sizeOfHFileRefsQueueGauge.decr(size);
214   }
215 
216   @Override
217   public int getSizeOfLogQueue() {
218     return (int)sizeOfLogQueueGauge.value();
219   }
220 
221   @Override
222   public void incrUnknownFileLengthForClosedWAL() {
223     unknownFileLengthForClosedWAL.incr(1L);
224   }
225 
226   @Override
227   public void incrUncleanlyClosedWALs() {
228     uncleanlyClosedWAL.incr(1L);
229   }
230 
231   @Override
232   public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
233     uncleanlyClosedSkippedBytes.incr(bytes);
234   }
235 
236   @Override
237   public void incrRestartedWALReading() {
238     restartWALReading.incr(1L);
239   }
240 
241   @Override
242   public void incrRepeatedFileBytes(final long bytes) {
243     repeatedFileBytes.incr(bytes);
244   }
245 
246   @Override
247   public void incrCompletedWAL() {
248     completedWAL.incr(1L);
249   }
250 
251   @Override
252   public void incrCompletedRecoveryQueue() {
253     completedRecoveryQueue.incr(1L);
254   }
255 
256   @Override
257   public void incrFailedRecoveryQueue() {/*no op*/}
258 
259   @Override
260   public void init() {
261     rms.init();
262   }
263 
264   @Override
265   public void setGauge(String gaugeName, long value) {
266     rms.setGauge(this.keyPrefix + gaugeName, value);
267   }
268 
269   @Override
270   public void incGauge(String gaugeName, long delta) {
271     rms.incGauge(this.keyPrefix + gaugeName, delta);
272   }
273 
274   @Override
275   public void decGauge(String gaugeName, long delta) {
276     rms.decGauge(this.keyPrefix + gaugeName, delta);
277   }
278 
279   @Override
280   public void removeMetric(String key) {
281     rms.removeMetric(this.keyPrefix + key);
282   }
283 
284   @Override
285   public void incCounters(String counterName, long delta) {
286     rms.incCounters(this.keyPrefix + counterName, delta);
287   }
288 
289   @Override
290   public void updateHistogram(String name, long value) {
291     rms.updateHistogram(this.keyPrefix + name, value);
292   }
293 
294   @Override
295   public String getMetricsContext() {
296     return rms.getMetricsContext();
297   }
298 
299   @Override
300   public String getMetricsDescription() {
301     return rms.getMetricsDescription();
302   }
303 
304   @Override
305   public String getMetricsJmxContext() {
306     return rms.getMetricsJmxContext();
307   }
308 
309   @Override
310   public String getMetricsName() {
311     return rms.getMetricsName();
312   }
313 
314   @Override
315   public MetricRegistryInfo getMetricRegistryInfo() {
316     return new MetricRegistryInfo(getMetricsName(), getMetricsDescription(),
317       getMetricsContext(), getMetricsJmxContext(), true);
318   }
319 }