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  
36    public MetricsReplicationGlobalSourceSource(MetricsReplicationSourceImpl rms) {
37      this.rms = rms;
38  
39      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_AGE_OF_LAST_SHIPPED_OP, 0L);
40  
41      sizeOfLogQueueGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_SIZE_OF_LOG_QUEUE, 0L);
42  
43      shippedBatchesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_BATCHES, 0L);
44  
45      shippedOpsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_OPS, 0L);
46  
47      shippedKBsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_KBS, 0L);
48  
49      logReadInBytesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_BYTES, 0L);
50  
51      logReadInEditsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_EDITS, 0L);
52  
53      logEditsFilteredCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_EDITS_FILTERED, 0L);
54    }
55  
56    @Override public void setLastShippedAge(long age) {
57      ageOfLastShippedOpGauge.set(age);
58    }
59  
60    @Override public void setSizeOfLogQueue(int size) {
61      sizeOfLogQueueGauge.set(size);
62    }
63  
64    @Override public void incrSizeOfLogQueue(int size) {
65      sizeOfLogQueueGauge.incr(size);
66    }
67  
68    @Override public void decrSizeOfLogQueue(int size) {
69      sizeOfLogQueueGauge.decr(size);
70    }
71  
72    @Override public void incrLogReadInEdits(long size) {
73      logReadInEditsCounter.incr(size);
74    }
75  
76    @Override public void incrLogEditsFiltered(long size) {
77      logEditsFilteredCounter.incr(size);
78    }
79  
80    @Override public void incrBatchesShipped(int batches) {
81      shippedBatchesCounter.incr(batches);
82    }
83  
84    @Override public void incrOpsShipped(long ops) {
85      shippedOpsCounter.incr(ops);
86    }
87  
88    @Override public void incrShippedKBs(long size) {
89      shippedKBsCounter.incr(size);
90    }
91  
92    @Override public void incrLogReadInBytes(long size) {
93      logReadInBytesCounter.incr(size);
94    }
95  
96    @Override public void clear() {
97    }
98  
99    @Override
100   public long getLastShippedAge() {
101     return ageOfLastShippedOpGauge.value();
102   }
103 }