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.MutableFastCounter;
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 MutableFastCounter logReadInEditsCounter;
30    private final MutableFastCounter logEditsFilteredCounter;
31    private final MutableFastCounter shippedBatchesCounter;
32    private final MutableFastCounter shippedOpsCounter;
33    private final MutableFastCounter shippedKBsCounter;
34    private final MutableFastCounter logReadInBytesCounter;
35    private final MutableFastCounter shippedHFilesCounter;
36    private final MutableGaugeLong sizeOfHFileRefsQueueGauge;
37  
38    public MetricsReplicationGlobalSourceSource(MetricsReplicationSourceImpl rms) {
39      this.rms = rms;
40  
41      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getGauge(SOURCE_AGE_OF_LAST_SHIPPED_OP, 0L);
42  
43      sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(SOURCE_SIZE_OF_LOG_QUEUE, 0L);
44  
45      shippedBatchesCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_BATCHES, 0L);
46  
47      shippedOpsCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_OPS, 0L);
48  
49      shippedKBsCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_KBS, 0L);
50  
51      logReadInBytesCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_READ_IN_BYTES, 0L);
52  
53      logReadInEditsCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_READ_IN_EDITS, 0L);
54  
55      logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(SOURCE_LOG_EDITS_FILTERED, 0L);
56  
57      shippedHFilesCounter = rms.getMetricsRegistry().getCounter(SOURCE_SHIPPED_HFILES, 0L);
58  
59      sizeOfHFileRefsQueueGauge =
60          rms.getMetricsRegistry().getGauge(SOURCE_SIZE_OF_HFILE_REFS_QUEUE, 0L);
61    }
62  
63    @Override public void setLastShippedAge(long age) {
64      ageOfLastShippedOpGauge.set(age);
65    }
66  
67    @Override public void setSizeOfLogQueue(int size) {
68      sizeOfLogQueueGauge.set(size);
69    }
70  
71    @Override public void incrSizeOfLogQueue(int size) {
72      sizeOfLogQueueGauge.incr(size);
73    }
74  
75    @Override public void decrSizeOfLogQueue(int size) {
76      sizeOfLogQueueGauge.decr(size);
77    }
78  
79    @Override public void incrLogReadInEdits(long size) {
80      logReadInEditsCounter.incr(size);
81    }
82  
83    @Override public void incrLogEditsFiltered(long size) {
84      logEditsFilteredCounter.incr(size);
85    }
86  
87    @Override public void incrBatchesShipped(int batches) {
88      shippedBatchesCounter.incr(batches);
89    }
90  
91    @Override public void incrOpsShipped(long ops) {
92      shippedOpsCounter.incr(ops);
93    }
94  
95    @Override public void incrShippedKBs(long size) {
96      shippedKBsCounter.incr(size);
97    }
98  
99    @Override public void incrLogReadInBytes(long size) {
100     logReadInBytesCounter.incr(size);
101   }
102 
103   @Override public void clear() {
104   }
105 
106   @Override
107   public long getLastShippedAge() {
108     return ageOfLastShippedOpGauge.value();
109   }
110 
111   @Override public void incrHFilesShipped(long hfiles) {
112     shippedHFilesCounter.incr(hfiles);
113   }
114 
115   @Override
116   public void incrSizeOfHFileRefsQueue(long size) {
117     sizeOfHFileRefsQueueGauge.incr(size);
118   }
119 
120   @Override
121   public void decrSizeOfHFileRefsQueue(long size) {
122     sizeOfHFileRefsQueueGauge.decr(size);
123   }
124 }