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  
19  package org.apache.hadoop.hbase.replication.regionserver;
20  
21  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
22  import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
23  
24  public class MetricsReplicationGlobalSourceSource implements MetricsReplicationSourceSource{
25    private final MetricsReplicationSourceImpl rms;
26  
27    private final MutableGaugeLong ageOfLastShippedOpGauge;
28    private final MutableGaugeLong sizeOfLogQueueGauge;
29    private final MutableCounterLong logReadInEditsCounter;
30    private final MutableCounterLong logEditsFilteredCounter;
31    private final MutableCounterLong shippedBatchesCounter;
32    private final MutableCounterLong shippedOpsCounter;
33    private final MutableCounterLong shippedKBsCounter;
34    private final MutableCounterLong logReadInBytesCounter;
35    private final MutableCounterLong unknownFileLengthForClosedWAL;
36    private final MutableCounterLong uncleanlyClosedWAL;
37    private final MutableCounterLong uncleanlyClosedSkippedBytes;
38    private final MutableCounterLong restartWALReading;
39    private final MutableCounterLong repeatedFileBytes;
40    private final MutableCounterLong completedWAL;
41    private final MutableCounterLong completedRecoveryQueue;
42  
43    public MetricsReplicationGlobalSourceSource(MetricsReplicationSourceImpl rms) {
44      this.rms = rms;
45  
46      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_AGE_OF_LAST_SHIPPED_OP, 0L);
47  
48      sizeOfLogQueueGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_SIZE_OF_LOG_QUEUE, 0L);
49  
50      shippedBatchesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_BATCHES, 0L);
51  
52      shippedOpsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_OPS, 0L);
53  
54      shippedKBsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_KBS, 0L);
55  
56      logReadInBytesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_BYTES, 0L);
57  
58      logReadInEditsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_EDITS, 0L);
59  
60      logEditsFilteredCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_EDITS_FILTERED, 0L);
61      unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_CLOSED_LOGS_WITH_UNKNOWN_LENGTH, 0L);
62      uncleanlyClosedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_UNCLEANLY_CLOSED_LOGS, 0L);
63      uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getLongCounter(SOURCE_UNCLEANLY_CLOSED_IGNORED_IN_BYTES, 0L);
64      restartWALReading = rms.getMetricsRegistry().getLongCounter(SOURCE_RESTARTED_LOG_READING, 0L);
65      repeatedFileBytes = rms.getMetricsRegistry().getLongCounter(SOURCE_REPEATED_LOG_FILE_BYTES, 0L);
66      completedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_COMPLETED_LOGS, 0L);
67      completedRecoveryQueue = rms.getMetricsRegistry().getLongCounter(SOURCE_COMPLETED_RECOVERY_QUEUES, 0L);
68    }
69  
70    @Override public void setLastShippedAge(long age) {
71      ageOfLastShippedOpGauge.set(age);
72    }
73  
74    @Override public void setSizeOfLogQueue(int size) {
75      sizeOfLogQueueGauge.set(size);
76    }
77  
78    @Override public void incrSizeOfLogQueue(int size) {
79      sizeOfLogQueueGauge.incr(size);
80    }
81  
82    @Override public void decrSizeOfLogQueue(int size) {
83      sizeOfLogQueueGauge.decr(size);
84    }
85  
86    @Override public void incrLogReadInEdits(long size) {
87      logReadInEditsCounter.incr(size);
88    }
89  
90    @Override public void incrLogEditsFiltered(long size) {
91      logEditsFilteredCounter.incr(size);
92    }
93  
94    @Override public void incrBatchesShipped(int batches) {
95      shippedBatchesCounter.incr(batches);
96    }
97  
98    @Override public void incrOpsShipped(long ops) {
99      shippedOpsCounter.incr(ops);
100   }
101 
102   @Override public void incrShippedKBs(long size) {
103     shippedKBsCounter.incr(size);
104   }
105 
106   @Override public void incrLogReadInBytes(long size) {
107     logReadInBytesCounter.incr(size);
108   }
109 
110   @Override public void clear() {
111   }
112 
113   @Override
114   public long getLastShippedAge() {
115     return ageOfLastShippedOpGauge.value();
116   }
117 
118   @Override
119   public void incrUnknownFileLengthForClosedWAL() {
120     unknownFileLengthForClosedWAL.incr(1L);
121   }
122   @Override
123   public void incrUncleanlyClosedWALs() {
124     uncleanlyClosedWAL.incr(1L);
125   }
126   @Override
127   public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
128     uncleanlyClosedSkippedBytes.incr(bytes);
129   }
130   @Override
131   public void incrRestartedWALReading() {
132     restartWALReading.incr(1L);
133   }
134   @Override
135   public void incrRepeatedFileBytes(final long bytes) {
136     repeatedFileBytes.incr(bytes);
137   }
138   @Override
139   public void incrCompletedWAL() {
140     completedWAL.incr(1L);
141   }
142   @Override
143   public void incrCompletedRecoveryQueue() {
144     completedRecoveryQueue.incr(1L);
145   }
146 
147 }