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