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