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  
62      unknownFileLengthForClosedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_CLOSED_LOGS_WITH_UNKNOWN_LENGTH, 0L);
63      uncleanlyClosedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_UNCLEANLY_CLOSED_LOGS, 0L);
64      uncleanlyClosedSkippedBytes = rms.getMetricsRegistry().getLongCounter(SOURCE_UNCLEANLY_CLOSED_IGNORED_IN_BYTES, 0L);
65      restartWALReading = rms.getMetricsRegistry().getLongCounter(SOURCE_RESTARTED_LOG_READING, 0L);
66      repeatedFileBytes = rms.getMetricsRegistry().getLongCounter(SOURCE_REPEATED_LOG_FILE_BYTES, 0L);
67      completedWAL = rms.getMetricsRegistry().getLongCounter(SOURCE_COMPLETED_LOGS, 0L);
68      completedRecoveryQueue = rms.getMetricsRegistry().getLongCounter(SOURCE_COMPLETED_RECOVERY_QUEUES, 0L);
69    }
70  
71    @Override public void setLastShippedAge(long age) {
72      ageOfLastShippedOpGauge.set(age);
73    }
74  
75    @Override public void setSizeOfLogQueue(int size) {
76      sizeOfLogQueueGauge.set(size);
77    }
78  
79    @Override public void incrSizeOfLogQueue(int size) {
80      sizeOfLogQueueGauge.incr(size);
81    }
82  
83    @Override public void decrSizeOfLogQueue(int size) {
84      sizeOfLogQueueGauge.decr(size);
85    }
86  
87    @Override public void incrLogReadInEdits(long size) {
88      logReadInEditsCounter.incr(size);
89    }
90  
91    @Override public void incrLogEditsFiltered(long size) {
92      logEditsFilteredCounter.incr(size);
93    }
94  
95    @Override public void incrBatchesShipped(int batches) {
96      shippedBatchesCounter.incr(batches);
97    }
98  
99    @Override public void incrOpsShipped(long ops) {
100     shippedOpsCounter.incr(ops);
101   }
102 
103   @Override public void incrShippedKBs(long size) {
104     shippedKBsCounter.incr(size);
105   }
106 
107   @Override public void incrLogReadInBytes(long size) {
108     logReadInBytesCounter.incr(size);
109   }
110 
111   @Override public void clear() {
112   }
113 
114   @Override
115   public long getLastShippedAge() {
116     return ageOfLastShippedOpGauge.value();
117   }
118 
119   @Override
120   public void incrUnknownFileLengthForClosedWAL() {
121     unknownFileLengthForClosedWAL.incr(1L);
122   }
123   @Override
124   public void incrUncleanlyClosedWALs() {
125     uncleanlyClosedWAL.incr(1L);
126   }
127   @Override
128   public void incrBytesSkippedInUncleanlyClosedWALs(final long bytes) {
129     uncleanlyClosedSkippedBytes.incr(bytes);
130   }
131   @Override
132   public void incrRestartedWALReading() {
133     restartWALReading.incr(1L);
134   }
135   @Override
136   public void incrRepeatedFileBytes(final long bytes) {
137     repeatedFileBytes.incr(bytes);
138   }
139   @Override
140   public void incrCompletedWAL() {
141     completedWAL.incr(1L);
142   }
143   @Override
144   public void incrCompletedRecoveryQueue() {
145     completedRecoveryQueue.incr(1L);
146   }
147 }