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.MetricMutableCounterLong;
22  import org.apache.hadoop.metrics2.lib.MetricMutableGaugeLong;
23  
24  public class MetricsReplicationGlobalSourceSource implements MetricsReplicationSourceSource {
25  
26    private final MetricMutableGaugeLong ageOfLastShippedOpGauge;
27    private long ageOfLastShipped; // Hadoop 1 metrics don't let you read from gauges
28    private final MetricMutableGaugeLong sizeOfLogQueueGauge;
29    private final MetricMutableCounterLong logReadInEditsCounter;
30    private final MetricMutableCounterLong logEditsFilteredCounter;
31    private final MetricMutableCounterLong shippedBatchesCounter;
32    private final MetricMutableCounterLong shippedOpsCounter;
33    private final MetricMutableCounterLong shippedKBsCounter;
34    private final MetricMutableCounterLong logReadInBytesCounter;
35  
36    public MetricsReplicationGlobalSourceSource(MetricsReplicationSourceImpl rms) {
37  
38      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_AGE_OF_LAST_SHIPPED_OP, 0L);
39  
40      sizeOfLogQueueGauge = rms.getMetricsRegistry().getLongGauge(SOURCE_SIZE_OF_LOG_QUEUE, 0L);
41  
42      shippedBatchesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_BATCHES, 0L);
43  
44      shippedOpsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_OPS, 0L);
45  
46      shippedKBsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_SHIPPED_KBS, 0L);
47  
48      logReadInBytesCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_BYTES, 0L);
49  
50      logReadInEditsCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_READ_IN_EDITS, 0L);
51  
52      logEditsFilteredCounter = rms.getMetricsRegistry().getLongCounter(SOURCE_LOG_EDITS_FILTERED, 0L);
53    }
54  
55    @Override public void setLastShippedAge(long age) {
56      ageOfLastShippedOpGauge.set(age);
57      ageOfLastShipped = 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 ageOfLastShipped;
102   }
103 }