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.regionserver;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.MetricHistogram;
24  import org.apache.hadoop.metrics2.MetricsCollector;
25  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
26  import org.apache.hadoop.metrics2.lib.Interns;
27  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
28  
29  /**
30   * Hadoop2 implementation of MetricsRegionServerSource.
31   *
32   * Implements BaseSource through BaseSourceImpl, following the pattern
33   */
34  @InterfaceAudience.Private
35  public class MetricsRegionServerSourceImpl
36      extends BaseSourceImpl implements MetricsRegionServerSource {
37  
38  
39    final MetricsRegionServerWrapper rsWrap;
40    private final MetricHistogram putHisto;
41    private final MetricHistogram deleteHisto;
42    private final MetricHistogram getHisto;
43    private final MetricHistogram incrementHisto;
44    private final MetricHistogram appendHisto;
45    private final MetricHistogram replayHisto;
46    private final MetricHistogram scanNextHisto;
47  
48    private final MutableCounterLong slowPut;
49    private final MutableCounterLong slowDelete;
50    private final MutableCounterLong slowGet;
51    private final MutableCounterLong slowIncrement;
52    private final MutableCounterLong slowAppend;
53    private final MutableCounterLong splitRequest;
54    private final MutableCounterLong splitSuccess;
55  
56    private final MetricHistogram splitTimeHisto;
57    private final MetricHistogram flushTimeHisto;
58  
59    public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
60      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
61    }
62  
63    public MetricsRegionServerSourceImpl(String metricsName,
64                                         String metricsDescription,
65                                         String metricsContext,
66                                         String metricsJmxContext,
67                                         MetricsRegionServerWrapper rsWrap) {
68      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
69      this.rsWrap = rsWrap;
70  
71      putHisto = getMetricsRegistry().newTimeHistogram(MUTATE_KEY);
72      slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0L);
73  
74      deleteHisto = getMetricsRegistry().newTimeHistogram(DELETE_KEY);
75      slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0L);
76  
77      getHisto = getMetricsRegistry().newTimeHistogram(GET_KEY);
78      slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0L);
79  
80      incrementHisto = getMetricsRegistry().newTimeHistogram(INCREMENT_KEY);
81      slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0L);
82  
83      appendHisto = getMetricsRegistry().newTimeHistogram(APPEND_KEY);
84      slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0L);
85      
86      replayHisto = getMetricsRegistry().newTimeHistogram(REPLAY_KEY);
87      scanNextHisto = getMetricsRegistry().newTimeHistogram(SCAN_NEXT_KEY);
88  
89      splitTimeHisto = getMetricsRegistry().newTimeHistogram(SPLIT_KEY);
90      flushTimeHisto = getMetricsRegistry().newTimeHistogram(FLUSH_KEY);
91  
92      splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0L);
93      splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0L);
94    }
95  
96    @Override
97    public void updatePut(long t) {
98      putHisto.add(t);
99    }
100 
101   @Override
102   public void updateDelete(long t) {
103     deleteHisto.add(t);
104   }
105 
106   @Override
107   public void updateGet(long t) {
108     getHisto.add(t);
109   }
110 
111   @Override
112   public void updateIncrement(long t) {
113     incrementHisto.add(t);
114   }
115 
116   @Override
117   public void updateAppend(long t) {
118     appendHisto.add(t);
119   }
120 
121   @Override
122   public void updateReplay(long t) {
123     replayHisto.add(t);
124   }
125 
126   @Override
127   public void updateScannerNext(long scanSize) {
128     scanNextHisto.add(scanSize);
129   }
130 
131   @Override
132   public void incrSlowPut() {
133    slowPut.incr();
134   }
135 
136   @Override
137   public void incrSlowDelete() {
138     slowDelete.incr();
139   }
140 
141   @Override
142   public void incrSlowGet() {
143     slowGet.incr();
144   }
145 
146   @Override
147   public void incrSlowIncrement() {
148     slowIncrement.incr();
149   }
150 
151   @Override
152   public void incrSlowAppend() {
153     slowAppend.incr();
154   }
155 
156   @Override
157   public void incrSplitRequest() {
158     splitRequest.incr();
159   }
160 
161   @Override
162   public void incrSplitSuccess() {
163     splitSuccess.incr();
164   }
165 
166   @Override
167   public void updateSplitTime(long t) {
168     splitTimeHisto.add(t);
169   }
170 
171   @Override
172   public void updateFlushTime(long t) {
173     flushTimeHisto.add(t);
174   }
175 
176   /**
177    * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
178    * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
179    * getMetrics to push the metrics into the collector.
180    *
181    * @param metricsCollector Collector to accept metrics
182    * @param all              push all or only changed?
183    */
184   @Override
185   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
186 
187     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
188 
189     // rsWrap can be null because this function is called inside of init.
190     if (rsWrap != null) {
191       mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
192           .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
193           .addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
194           .addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
195           .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
196           .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
197           .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
198           .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
199               rsWrap.getStartCode())
200           .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
201               rsWrap.getTotalRequestCount())
202           .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
203               rsWrap.getReadRequestsCount())
204           .addCounter(Interns.info(FILTERED_READ_REQUEST_COUNT, FILTERED_READ_REQUEST_COUNT_DESC),
205               rsWrap.getFilteredReadRequestsCount())
206           .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
207               rsWrap.getWriteRequestsCount())
208           .addCounter(Interns.info(RPC_GET_REQUEST_COUNT, RPC_GET_REQUEST_COUNT_DESC),
209             rsWrap.getRpcGetRequestsCount())
210           .addCounter(Interns.info(RPC_SCAN_REQUEST_COUNT, RPC_SCAN_REQUEST_COUNT_DESC),
211             rsWrap.getRpcScanRequestsCount())
212           .addCounter(Interns.info(RPC_MULTI_REQUEST_COUNT, RPC_MULTI_REQUEST_COUNT_DESC),
213             rsWrap.getRpcMultiRequestsCount())
214           .addCounter(Interns.info(RPC_MUTATE_REQUEST_COUNT, RPC_MUTATE_REQUEST_COUNT_DESC),
215             rsWrap.getRpcMutateRequestsCount())
216           .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
217               rsWrap.getCheckAndMutateChecksFailed())
218           .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
219               rsWrap.getCheckAndMutateChecksPassed())
220           .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
221               rsWrap.getStoreFileIndexSize())
222           .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
223               rsWrap.getTotalStaticIndexSize())
224           .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
225             rsWrap.getTotalStaticBloomSize())
226           .addGauge(
227             Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
228               rsWrap.getNumMutationsWithoutWAL())
229           .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
230               rsWrap.getDataInMemoryWithoutWAL())
231           .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
232               rsWrap.getPercentFileLocal())
233           .addGauge(Interns.info(PERCENT_FILES_LOCAL_SECONDARY_REGIONS,
234               PERCENT_FILES_LOCAL_SECONDARY_REGIONS_DESC),
235               rsWrap.getPercentFileLocalSecondaryRegions())
236           .addGauge(Interns.info(SPLIT_QUEUE_LENGTH, SPLIT_QUEUE_LENGTH_DESC),
237               rsWrap.getSplitQueueSize())
238           .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
239               rsWrap.getCompactionQueueSize())
240           .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
241               rsWrap.getFlushQueueSize())
242           .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
243               rsWrap.getBlockCacheFreeSize())
244           .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
245               rsWrap.getBlockCacheCount())
246           .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
247               rsWrap.getBlockCacheSize())
248           .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
249               rsWrap.getBlockCacheHitCount())
250           .addCounter(Interns.info(BLOCK_CACHE_PRIMARY_HIT_COUNT,
251             BLOCK_CACHE_PRIMARY_HIT_COUNT_DESC), rsWrap.getBlockCachePrimaryHitCount())
252           .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
253               rsWrap.getBlockCacheMissCount())
254           .addCounter(Interns.info(BLOCK_CACHE_PRIMARY_MISS_COUNT,
255             BLOCK_COUNT_PRIMARY_MISS_COUNT_DESC), rsWrap.getBlockCachePrimaryMissCount())
256           .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
257               rsWrap.getBlockCacheEvictedCount())
258           .addCounter(Interns.info(BLOCK_CACHE_PRIMARY_EVICTION_COUNT,
259             BLOCK_CACHE_PRIMARY_EVICTION_COUNT_DESC), rsWrap.getBlockCachePrimaryEvictedCount())
260           .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
261               rsWrap.getBlockCacheHitPercent())
262           .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
263               BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
264           .addCounter(Interns.info(BLOCK_CACHE_FAILED_INSERTION_COUNT,
265               BLOCK_CACHE_FAILED_INSERTION_COUNT_DESC),rsWrap.getBlockCacheFailedInsertions())
266           .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
267               rsWrap.getUpdatesBlockedTime())
268           .addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
269               rsWrap.getFlushedCellsCount())
270           .addCounter(Interns.info(COMPACTED_CELLS, COMPACTED_CELLS_DESC),
271               rsWrap.getCompactedCellsCount())
272           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS, MAJOR_COMPACTED_CELLS_DESC),
273               rsWrap.getMajorCompactedCellsCount())
274           .addCounter(Interns.info(FLUSHED_CELLS_SIZE, FLUSHED_CELLS_SIZE_DESC),
275               rsWrap.getFlushedCellsSize())
276           .addCounter(Interns.info(COMPACTED_CELLS_SIZE, COMPACTED_CELLS_SIZE_DESC),
277               rsWrap.getCompactedCellsSize())
278           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS_SIZE, MAJOR_COMPACTED_CELLS_SIZE_DESC),
279               rsWrap.getMajorCompactedCellsSize())
280 
281           .addCounter(
282               Interns.info(CELLS_COUNT_COMPACTED_FROM_MOB, CELLS_COUNT_COMPACTED_FROM_MOB_DESC),
283               rsWrap.getCellsCountCompactedFromMob())
284           .addCounter(Interns.info(CELLS_COUNT_COMPACTED_TO_MOB, CELLS_COUNT_COMPACTED_TO_MOB_DESC),
285               rsWrap.getCellsCountCompactedToMob())
286           .addCounter(
287               Interns.info(CELLS_SIZE_COMPACTED_FROM_MOB, CELLS_SIZE_COMPACTED_FROM_MOB_DESC),
288               rsWrap.getCellsSizeCompactedFromMob())
289           .addCounter(Interns.info(CELLS_SIZE_COMPACTED_TO_MOB, CELLS_SIZE_COMPACTED_TO_MOB_DESC),
290               rsWrap.getCellsSizeCompactedToMob())
291           .addCounter(Interns.info(MOB_FLUSH_COUNT, MOB_FLUSH_COUNT_DESC),
292               rsWrap.getMobFlushCount())
293           .addCounter(Interns.info(MOB_FLUSHED_CELLS_COUNT, MOB_FLUSHED_CELLS_COUNT_DESC),
294               rsWrap.getMobFlushedCellsCount())
295           .addCounter(Interns.info(MOB_FLUSHED_CELLS_SIZE, MOB_FLUSHED_CELLS_SIZE_DESC),
296               rsWrap.getMobFlushedCellsSize())
297           .addCounter(Interns.info(MOB_SCAN_CELLS_COUNT, MOB_SCAN_CELLS_COUNT_DESC),
298               rsWrap.getMobScanCellsCount())
299           .addCounter(Interns.info(MOB_SCAN_CELLS_SIZE, MOB_SCAN_CELLS_SIZE_DESC),
300               rsWrap.getMobScanCellsSize())
301           .addGauge(Interns.info(MOB_FILE_CACHE_COUNT, MOB_FILE_CACHE_COUNT_DESC),
302               rsWrap.getMobFileCacheCount())
303           .addCounter(Interns.info(MOB_FILE_CACHE_ACCESS_COUNT, MOB_FILE_CACHE_ACCESS_COUNT_DESC),
304               rsWrap.getMobFileCacheAccessCount())
305           .addCounter(Interns.info(MOB_FILE_CACHE_MISS_COUNT, MOB_FILE_CACHE_MISS_COUNT_DESC),
306               rsWrap.getMobFileCacheMissCount())
307           .addCounter(
308               Interns.info(MOB_FILE_CACHE_EVICTED_COUNT, MOB_FILE_CACHE_EVICTED_COUNT_DESC),
309               rsWrap.getMobFileCacheEvictedCount())
310           .addGauge(Interns.info(MOB_FILE_CACHE_HIT_PERCENT, MOB_FILE_CACHE_HIT_PERCENT_DESC),
311               rsWrap.getMobFileCacheHitPercent())
312 
313           .addCounter(Interns.info(HEDGED_READS, HEDGED_READS_DESC), rsWrap.getHedgedReadOps())
314           .addCounter(Interns.info(HEDGED_READ_WINS, HEDGED_READ_WINS_DESC),
315               rsWrap.getHedgedReadWins())
316 
317           .addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
318             rsWrap.getBlockedRequestsCount())
319 
320           .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
321               rsWrap.getZookeeperQuorum())
322           .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
323           .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
324     }
325 
326     metricsRegistry.snapshot(mrb, all);
327   }
328 }