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