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