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