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 MetricsReplicationSourceSourceImpl implements MetricsReplicationSourceSource {
25  
26    private final MetricsReplicationSourceImpl rms;
27    private final String id;
28    private final String sizeOfLogQueueKey;
29    private final String ageOfLastShippedOpKey;
30    private final String logReadInEditsKey;
31    private final String logEditsFilteredKey;
32    private final String shippedBatchesKey;
33    private final String shippedOpsKey;
34    private final String shippedKBsKey;
35    private final String logReadInBytesKey;
36  
37    private final MutableGaugeLong ageOfLastShippedOpGauge;
38    private final MutableGaugeLong sizeOfLogQueueGauge;
39    private final MutableCounterLong logReadInEditsCounter;
40    private final MutableCounterLong logEditsFilteredCounter;
41    private final MutableCounterLong shippedBatchesCounter;
42    private final MutableCounterLong shippedOpsCounter;
43    private final MutableCounterLong shippedKBsCounter;
44    private final MutableCounterLong logReadInBytesCounter;
45  
46    public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) {
47      this.rms = rms;
48      this.id = id;
49  
50      ageOfLastShippedOpKey = "source." + id + ".ageOfLastShippedOp";
51      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getLongGauge(ageOfLastShippedOpKey, 0L);
52  
53      sizeOfLogQueueKey = "source." + id + ".sizeOfLogQueue";
54      sizeOfLogQueueGauge = rms.getMetricsRegistry().getLongGauge(sizeOfLogQueueKey, 0L);
55  
56      shippedBatchesKey = "source." + this.id + ".shippedBatches";
57      shippedBatchesCounter = rms.getMetricsRegistry().getLongCounter(shippedBatchesKey, 0L);
58  
59      shippedOpsKey = "source." + this.id + ".shippedOps";
60      shippedOpsCounter = rms.getMetricsRegistry().getLongCounter(shippedOpsKey, 0L);
61  
62      shippedKBsKey = "source." + this.id + ".shippedKBs";
63      shippedKBsCounter = rms.getMetricsRegistry().getLongCounter(shippedKBsKey, 0L);
64  
65      logReadInBytesKey = "source." + this.id + ".logReadInBytes";
66      logReadInBytesCounter = rms.getMetricsRegistry().getLongCounter(logReadInBytesKey, 0L);
67  
68      logReadInEditsKey = "source." + id + ".logEditsRead";
69      logReadInEditsCounter = rms.getMetricsRegistry().getLongCounter(logReadInEditsKey, 0L);
70  
71      logEditsFilteredKey = "source." + id + ".logEditsFiltered";
72      logEditsFilteredCounter = rms.getMetricsRegistry().getLongCounter(logEditsFilteredKey, 0L);
73    }
74  
75    @Override public void setLastShippedAge(long age) {
76      ageOfLastShippedOpGauge.set(age);
77    }
78  
79    @Override public void setSizeOfLogQueue(int size) {
80      sizeOfLogQueueGauge.set(size);
81    }
82  
83    @Override public void incrSizeOfLogQueue(int size) {
84      sizeOfLogQueueGauge.incr(size);
85    }
86  
87    @Override public void decrSizeOfLogQueue(int size) {
88      sizeOfLogQueueGauge.decr(size);
89    }
90  
91    @Override public void incrLogReadInEdits(long size) {
92      logReadInEditsCounter.incr(size);
93    }
94  
95    @Override public void incrLogEditsFiltered(long size) {
96      logEditsFilteredCounter.incr(size);
97    }
98  
99    @Override public void incrBatchesShipped(int batches) {
100     shippedBatchesCounter.incr(batches);
101   }
102 
103   @Override public void incrOpsShipped(long ops) {
104     shippedOpsCounter.incr(ops);
105   }
106 
107   @Override public void incrShippedKBs(long size) {
108     shippedKBsCounter.incr(size);
109   }
110 
111   @Override public void incrLogReadInBytes(long size) {
112     logReadInBytesCounter.incr(size);
113   }
114 
115   @Override public void clear() {
116     rms.removeMetric(ageOfLastShippedOpKey);
117 
118     rms.removeMetric(sizeOfLogQueueKey);
119 
120     rms.removeMetric(shippedBatchesKey);
121     rms.removeMetric(shippedOpsKey);
122     rms.removeMetric(shippedKBsKey);
123 
124     rms.removeMetric(logReadInBytesKey);
125     rms.removeMetric(logReadInEditsKey);
126 
127     rms.removeMetric(logEditsFilteredKey);
128   }
129 
130   @Override
131   public long getLastShippedAge() {
132     return ageOfLastShippedOpGauge.value();
133   }
134 }