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.MutableFastCounter;
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    private final String shippedHFilesKey;
36    private final String sizeOfHFileRefsQueueKey;
37  
38    private final MutableGaugeLong ageOfLastShippedOpGauge;
39    private final MutableGaugeLong sizeOfLogQueueGauge;
40    private final MutableFastCounter logReadInEditsCounter;
41    private final MutableFastCounter logEditsFilteredCounter;
42    private final MutableFastCounter shippedBatchesCounter;
43    private final MutableFastCounter shippedOpsCounter;
44    private final MutableFastCounter shippedKBsCounter;
45    private final MutableFastCounter logReadInBytesCounter;
46    private final MutableFastCounter shippedHFilesCounter;
47    private final MutableGaugeLong sizeOfHFileRefsQueueGauge;
48  
49    public MetricsReplicationSourceSourceImpl(MetricsReplicationSourceImpl rms, String id) {
50      this.rms = rms;
51      this.id = id;
52  
53      ageOfLastShippedOpKey = "source." + id + ".ageOfLastShippedOp";
54      ageOfLastShippedOpGauge = rms.getMetricsRegistry().getGauge(ageOfLastShippedOpKey, 0L);
55  
56      sizeOfLogQueueKey = "source." + id + ".sizeOfLogQueue";
57      sizeOfLogQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfLogQueueKey, 0L);
58  
59      shippedBatchesKey = "source." + this.id + ".shippedBatches";
60      shippedBatchesCounter = rms.getMetricsRegistry().getCounter(shippedBatchesKey, 0L);
61  
62      shippedOpsKey = "source." + this.id + ".shippedOps";
63      shippedOpsCounter = rms.getMetricsRegistry().getCounter(shippedOpsKey, 0L);
64  
65      shippedKBsKey = "source." + this.id + ".shippedKBs";
66      shippedKBsCounter = rms.getMetricsRegistry().getCounter(shippedKBsKey, 0L);
67  
68      logReadInBytesKey = "source." + this.id + ".logReadInBytes";
69      logReadInBytesCounter = rms.getMetricsRegistry().getCounter(logReadInBytesKey, 0L);
70  
71      logReadInEditsKey = "source." + id + ".logEditsRead";
72      logReadInEditsCounter = rms.getMetricsRegistry().getCounter(logReadInEditsKey, 0L);
73  
74      logEditsFilteredKey = "source." + id + ".logEditsFiltered";
75      logEditsFilteredCounter = rms.getMetricsRegistry().getCounter(logEditsFilteredKey, 0L);
76  
77      shippedHFilesKey = "source." + this.id + ".shippedHFiles";
78      shippedHFilesCounter = rms.getMetricsRegistry().getCounter(shippedHFilesKey, 0L);
79  
80      sizeOfHFileRefsQueueKey = "source." + id + ".sizeOfHFileRefsQueue";
81      sizeOfHFileRefsQueueGauge = rms.getMetricsRegistry().getGauge(sizeOfHFileRefsQueueKey, 0L);
82    }
83  
84    @Override public void setLastShippedAge(long age) {
85      ageOfLastShippedOpGauge.set(age);
86    }
87  
88    @Override public void setSizeOfLogQueue(int size) {
89      sizeOfLogQueueGauge.set(size);
90    }
91  
92    @Override public void incrSizeOfLogQueue(int size) {
93      sizeOfLogQueueGauge.incr(size);
94    }
95  
96    @Override public void decrSizeOfLogQueue(int size) {
97      sizeOfLogQueueGauge.decr(size);
98    }
99  
100   @Override public void incrLogReadInEdits(long size) {
101     logReadInEditsCounter.incr(size);
102   }
103 
104   @Override public void incrLogEditsFiltered(long size) {
105     logEditsFilteredCounter.incr(size);
106   }
107 
108   @Override public void incrBatchesShipped(int batches) {
109     shippedBatchesCounter.incr(batches);
110   }
111 
112   @Override public void incrOpsShipped(long ops) {
113     shippedOpsCounter.incr(ops);
114   }
115 
116   @Override public void incrShippedKBs(long size) {
117     shippedKBsCounter.incr(size);
118   }
119 
120   @Override public void incrLogReadInBytes(long size) {
121     logReadInBytesCounter.incr(size);
122   }
123 
124   @Override public void clear() {
125     rms.removeMetric(ageOfLastShippedOpKey);
126 
127     rms.removeMetric(sizeOfLogQueueKey);
128 
129     rms.removeMetric(shippedBatchesKey);
130     rms.removeMetric(shippedOpsKey);
131     rms.removeMetric(shippedKBsKey);
132 
133     rms.removeMetric(logReadInBytesKey);
134     rms.removeMetric(logReadInEditsKey);
135 
136     rms.removeMetric(logEditsFilteredKey);
137 
138     rms.removeMetric(shippedHFilesKey);
139     rms.removeMetric(sizeOfHFileRefsQueueKey);
140   }
141 
142   @Override
143   public long getLastShippedAge() {
144     return ageOfLastShippedOpGauge.value();
145   }
146 
147   @Override
148   public void incrHFilesShipped(long hfiles) {
149     shippedHFilesCounter.incr(hfiles);
150   }
151 
152   @Override
153   public void incrSizeOfHFileRefsQueue(long size) {
154     sizeOfHFileRefsQueueGauge.incr(size);
155   }
156 
157   @Override
158   public void decrSizeOfHFileRefsQueue(long size) {
159     sizeOfHFileRefsQueueGauge.decr(size);
160   }
161 }