001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
021import org.apache.hadoop.hbase.metrics.Interns;
022import org.apache.hadoop.metrics2.MetricHistogram;
023import org.apache.hadoop.metrics2.MetricsCollector;
024import org.apache.hadoop.metrics2.MetricsRecordBuilder;
025import org.apache.hadoop.metrics2.lib.MutableFastCounter;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Hadoop2 implementation of MetricsRegionServerSource. Implements BaseSource through
030 * BaseSourceImpl, following the pattern
031 */
032@InterfaceAudience.Private
033public class MetricsRegionServerSourceImpl extends BaseSourceImpl
034  implements MetricsRegionServerSource {
035
036  final MetricsRegionServerWrapper rsWrap;
037  private final MetricHistogram putHisto;
038  private final MetricHistogram putBatchHisto;
039  private final MetricHistogram deleteHisto;
040  private final MetricHistogram deleteBatchHisto;
041  private final MetricHistogram checkAndDeleteHisto;
042  private final MetricHistogram checkAndPutHisto;
043  private final MetricHistogram checkAndMutateHisto;
044  private final MetricHistogram getHisto;
045  private final MetricHistogram incrementHisto;
046  private final MetricHistogram appendHisto;
047  private final MetricHistogram replayHisto;
048  private final MetricHistogram scanSizeHisto;
049  private final MetricHistogram scanTimeHisto;
050
051  private final MutableFastCounter blockBytesScannedCount;
052  private final MetricHistogram checkAndMutateBlockBytesScanned;
053  private final MetricHistogram getBlockBytesScanned;
054  private final MetricHistogram incrementBlockBytesScanned;
055  private final MetricHistogram appendBlockBytesScanned;
056  private final MetricHistogram scanBlockBytesScanned;
057
058  private final MutableFastCounter slowPut;
059  private final MutableFastCounter slowDelete;
060  private final MutableFastCounter slowGet;
061  private final MutableFastCounter slowIncrement;
062  private final MutableFastCounter slowAppend;
063
064  // split related metrics
065  private final MutableFastCounter splitRequest;
066  private final MutableFastCounter splitSuccess;
067  private final MetricHistogram splitTimeHisto;
068
069  // flush related metrics
070  private final MetricHistogram flushTimeHisto;
071  private final MetricHistogram flushMemstoreSizeHisto;
072  private final MetricHistogram flushOutputSizeHisto;
073  private final MutableFastCounter flushedMemstoreBytes;
074  private final MutableFastCounter flushedOutputBytes;
075
076  // compaction related metrics
077  private final MetricHistogram compactionTimeHisto;
078  private final MetricHistogram compactionInputFileCountHisto;
079  private final MetricHistogram compactionInputSizeHisto;
080  private final MetricHistogram compactionOutputFileCountHisto;
081  private final MetricHistogram compactionOutputSizeHisto;
082  private final MutableFastCounter compactedInputBytes;
083  private final MutableFastCounter compactedOutputBytes;
084
085  private final MetricHistogram majorCompactionTimeHisto;
086  private final MetricHistogram majorCompactionInputFileCountHisto;
087  private final MetricHistogram majorCompactionInputSizeHisto;
088  private final MetricHistogram majorCompactionOutputFileCountHisto;
089  private final MetricHistogram majorCompactionOutputSizeHisto;
090  private final MutableFastCounter majorCompactedInputBytes;
091  private final MutableFastCounter majorCompactedOutputBytes;
092
093  // pause monitor metrics
094  private final MutableFastCounter infoPauseThresholdExceeded;
095  private final MutableFastCounter warnPauseThresholdExceeded;
096  private final MetricHistogram pausesWithGc;
097  private final MetricHistogram pausesWithoutGc;
098
099  private final MutableFastCounter scannerLeaseExpiredCount;
100
101  public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
102    this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
103  }
104
105  public MetricsRegionServerSourceImpl(String metricsName, String metricsDescription,
106    String metricsContext, String metricsJmxContext, MetricsRegionServerWrapper rsWrap) {
107    super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
108    this.rsWrap = rsWrap;
109
110    putHisto = getMetricsRegistry().newTimeHistogram(PUT_KEY);
111    putBatchHisto = getMetricsRegistry().newTimeHistogram(PUT_BATCH_KEY);
112    slowPut = getMetricsRegistry().newCounter(SLOW_PUT_KEY, SLOW_PUT_DESC, 0L);
113
114    deleteHisto = getMetricsRegistry().newTimeHistogram(DELETE_KEY);
115    slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0L);
116
117    deleteBatchHisto = getMetricsRegistry().newTimeHistogram(DELETE_BATCH_KEY);
118    checkAndDeleteHisto = getMetricsRegistry().newTimeHistogram(CHECK_AND_DELETE_KEY);
119    checkAndPutHisto = getMetricsRegistry().newTimeHistogram(CHECK_AND_PUT_KEY);
120    checkAndMutateHisto = getMetricsRegistry().newTimeHistogram(CHECK_AND_MUTATE_KEY);
121
122    getHisto = getMetricsRegistry().newTimeHistogram(GET_KEY);
123    slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0L);
124
125    incrementHisto = getMetricsRegistry().newTimeHistogram(INCREMENT_KEY);
126    slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0L);
127
128    appendHisto = getMetricsRegistry().newTimeHistogram(APPEND_KEY);
129    slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0L);
130
131    replayHisto = getMetricsRegistry().newTimeHistogram(REPLAY_KEY);
132    scanSizeHisto = getMetricsRegistry().newSizeHistogram(SCAN_SIZE_KEY);
133    scanTimeHisto = getMetricsRegistry().newTimeHistogram(SCAN_TIME_KEY);
134
135    blockBytesScannedCount =
136      getMetricsRegistry().newCounter(BLOCK_BYTES_SCANNED_KEY, BLOCK_BYTES_SCANNED_DESC, 0L);
137    checkAndMutateBlockBytesScanned =
138      getMetricsRegistry().newSizeHistogram(CHECK_AND_MUTATE_BLOCK_BYTES_SCANNED_KEY);
139    getBlockBytesScanned = getMetricsRegistry().newSizeHistogram(GET_BLOCK_BYTES_SCANNED_KEY);
140    incrementBlockBytesScanned =
141      getMetricsRegistry().newSizeHistogram(INCREMENT_BLOCK_BYTES_SCANNED_KEY);
142    appendBlockBytesScanned = getMetricsRegistry().newSizeHistogram(APPEND_BLOCK_BYTES_SCANNED_KEY);
143    scanBlockBytesScanned = getMetricsRegistry().newSizeHistogram(SCAN_BLOCK_BYTES_SCANNED_KEY);
144
145    flushTimeHisto = getMetricsRegistry().newTimeHistogram(FLUSH_TIME, FLUSH_TIME_DESC);
146    flushMemstoreSizeHisto =
147      getMetricsRegistry().newSizeHistogram(FLUSH_MEMSTORE_SIZE, FLUSH_MEMSTORE_SIZE_DESC);
148    flushOutputSizeHisto =
149      getMetricsRegistry().newSizeHistogram(FLUSH_OUTPUT_SIZE, FLUSH_OUTPUT_SIZE_DESC);
150    flushedOutputBytes =
151      getMetricsRegistry().newCounter(FLUSHED_OUTPUT_BYTES, FLUSHED_OUTPUT_BYTES_DESC, 0L);
152    flushedMemstoreBytes =
153      getMetricsRegistry().newCounter(FLUSHED_MEMSTORE_BYTES, FLUSHED_MEMSTORE_BYTES_DESC, 0L);
154
155    compactionTimeHisto =
156      getMetricsRegistry().newTimeHistogram(COMPACTION_TIME, COMPACTION_TIME_DESC);
157    compactionInputFileCountHisto = getMetricsRegistry().newHistogram(COMPACTION_INPUT_FILE_COUNT,
158      COMPACTION_INPUT_FILE_COUNT_DESC);
159    compactionInputSizeHisto =
160      getMetricsRegistry().newSizeHistogram(COMPACTION_INPUT_SIZE, COMPACTION_INPUT_SIZE_DESC);
161    compactionOutputFileCountHisto = getMetricsRegistry().newHistogram(COMPACTION_OUTPUT_FILE_COUNT,
162      COMPACTION_OUTPUT_FILE_COUNT_DESC);
163    compactionOutputSizeHisto =
164      getMetricsRegistry().newSizeHistogram(COMPACTION_OUTPUT_SIZE, COMPACTION_OUTPUT_SIZE_DESC);
165    compactedInputBytes =
166      getMetricsRegistry().newCounter(COMPACTED_INPUT_BYTES, COMPACTED_INPUT_BYTES_DESC, 0L);
167    compactedOutputBytes =
168      getMetricsRegistry().newCounter(COMPACTED_OUTPUT_BYTES, COMPACTED_OUTPUT_BYTES_DESC, 0L);
169
170    majorCompactionTimeHisto =
171      getMetricsRegistry().newTimeHistogram(MAJOR_COMPACTION_TIME, MAJOR_COMPACTION_TIME_DESC);
172    majorCompactionInputFileCountHisto = getMetricsRegistry()
173      .newHistogram(MAJOR_COMPACTION_INPUT_FILE_COUNT, MAJOR_COMPACTION_INPUT_FILE_COUNT_DESC);
174    majorCompactionInputSizeHisto = getMetricsRegistry()
175      .newSizeHistogram(MAJOR_COMPACTION_INPUT_SIZE, MAJOR_COMPACTION_INPUT_SIZE_DESC);
176    majorCompactionOutputFileCountHisto = getMetricsRegistry()
177      .newHistogram(MAJOR_COMPACTION_OUTPUT_FILE_COUNT, MAJOR_COMPACTION_OUTPUT_FILE_COUNT_DESC);
178    majorCompactionOutputSizeHisto = getMetricsRegistry()
179      .newSizeHistogram(MAJOR_COMPACTION_OUTPUT_SIZE, MAJOR_COMPACTION_OUTPUT_SIZE_DESC);
180    majorCompactedInputBytes = getMetricsRegistry().newCounter(MAJOR_COMPACTED_INPUT_BYTES,
181      MAJOR_COMPACTED_INPUT_BYTES_DESC, 0L);
182    majorCompactedOutputBytes = getMetricsRegistry().newCounter(MAJOR_COMPACTED_OUTPUT_BYTES,
183      MAJOR_COMPACTED_OUTPUT_BYTES_DESC, 0L);
184
185    splitTimeHisto = getMetricsRegistry().newTimeHistogram(SPLIT_KEY);
186    splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0L);
187    splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0L);
188
189    // pause monitor metrics
190    infoPauseThresholdExceeded =
191      getMetricsRegistry().newCounter(INFO_THRESHOLD_COUNT_KEY, INFO_THRESHOLD_COUNT_DESC, 0L);
192    warnPauseThresholdExceeded =
193      getMetricsRegistry().newCounter(WARN_THRESHOLD_COUNT_KEY, WARN_THRESHOLD_COUNT_DESC, 0L);
194    pausesWithGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITH_GC_KEY);
195    pausesWithoutGc = getMetricsRegistry().newTimeHistogram(PAUSE_TIME_WITHOUT_GC_KEY);
196
197    scannerLeaseExpiredCount = getMetricsRegistry().newCounter(SCANNER_LEASE_EXPIRED_COUNT,
198      SCANNER_LEASE_EXPIRED_COUNT_DESC, 0L);
199  }
200
201  @Override
202  public void updatePut(long t) {
203    putHisto.add(t);
204  }
205
206  @Override
207  public void updateDelete(long t) {
208    deleteHisto.add(t);
209  }
210
211  @Override
212  public void updateGet(long t, long blockBytesScanned) {
213    getHisto.add(t);
214    if (blockBytesScanned > 0) {
215      blockBytesScannedCount.incr(blockBytesScanned);
216      getBlockBytesScanned.add(blockBytesScanned);
217    }
218  }
219
220  @Override
221  public void updateIncrement(long t, long blockBytesScanned) {
222    incrementHisto.add(t);
223    if (blockBytesScanned > 0) {
224      blockBytesScannedCount.incr(blockBytesScanned);
225      incrementBlockBytesScanned.add(blockBytesScanned);
226    }
227  }
228
229  @Override
230  public void updateAppend(long t, long blockBytesScanned) {
231    appendHisto.add(t);
232    if (blockBytesScanned > 0) {
233      blockBytesScannedCount.incr(blockBytesScanned);
234      appendBlockBytesScanned.add(blockBytesScanned);
235    }
236  }
237
238  @Override
239  public void updateReplay(long t) {
240    replayHisto.add(t);
241  }
242
243  @Override
244  public void updateScan(long time, long responseSize, long blockBytesScanned) {
245    scanTimeHisto.add(time);
246    scanSizeHisto.add(responseSize);
247    if (blockBytesScanned > 0) {
248      blockBytesScannedCount.incr(blockBytesScanned);
249      scanBlockBytesScanned.add(blockBytesScanned);
250    }
251  }
252
253  @Override
254  public void incrSlowPut() {
255    slowPut.incr();
256  }
257
258  @Override
259  public void incrSlowDelete() {
260    slowDelete.incr();
261  }
262
263  @Override
264  public void incrSlowGet() {
265    slowGet.incr();
266  }
267
268  @Override
269  public void incrSlowIncrement() {
270    slowIncrement.incr();
271  }
272
273  @Override
274  public void incrSlowAppend() {
275    slowAppend.incr();
276  }
277
278  @Override
279  public void incrSplitRequest() {
280    splitRequest.incr();
281  }
282
283  @Override
284  public void incrSplitSuccess() {
285    splitSuccess.incr();
286  }
287
288  @Override
289  public void updateSplitTime(long t) {
290    splitTimeHisto.add(t);
291  }
292
293  @Override
294  public void updateFlushTime(long t) {
295    flushTimeHisto.add(t);
296  }
297
298  @Override
299  public void updateFlushMemStoreSize(long bytes) {
300    flushMemstoreSizeHisto.add(bytes);
301    flushedMemstoreBytes.incr(bytes);
302  }
303
304  @Override
305  public void updateFlushOutputSize(long bytes) {
306    flushOutputSizeHisto.add(bytes);
307    flushedOutputBytes.incr(bytes);
308  }
309
310  @Override
311  public void updateCompactionTime(boolean isMajor, long t) {
312    compactionTimeHisto.add(t);
313    if (isMajor) {
314      majorCompactionTimeHisto.add(t);
315    }
316  }
317
318  @Override
319  public void updateCompactionInputFileCount(boolean isMajor, long c) {
320    compactionInputFileCountHisto.add(c);
321    if (isMajor) {
322      majorCompactionInputFileCountHisto.add(c);
323    }
324  }
325
326  @Override
327  public void updateCompactionInputSize(boolean isMajor, long bytes) {
328    compactionInputSizeHisto.add(bytes);
329    compactedInputBytes.incr(bytes);
330    if (isMajor) {
331      majorCompactionInputSizeHisto.add(bytes);
332      majorCompactedInputBytes.incr(bytes);
333    }
334  }
335
336  @Override
337  public void updateCompactionOutputFileCount(boolean isMajor, long c) {
338    compactionOutputFileCountHisto.add(c);
339    if (isMajor) {
340      majorCompactionOutputFileCountHisto.add(c);
341    }
342  }
343
344  @Override
345  public void updateCompactionOutputSize(boolean isMajor, long bytes) {
346    compactionOutputSizeHisto.add(bytes);
347    compactedOutputBytes.incr(bytes);
348    if (isMajor) {
349      majorCompactionOutputSizeHisto.add(bytes);
350      majorCompactedOutputBytes.incr(bytes);
351    }
352  }
353
354  @Override
355  public void incrScannerLeaseExpired() {
356    scannerLeaseExpiredCount.incr();
357  }
358
359  /**
360   * Yes this is a get function that doesn't return anything. Thanks Hadoop for breaking all
361   * expectations of java programmers. Instead of returning anything Hadoop metrics expects
362   * getMetrics to push the metrics into the collector.
363   * @param metricsCollector Collector to accept metrics
364   * @param all              push all or only changed?
365   */
366  @Override
367  public void getMetrics(MetricsCollector metricsCollector, boolean all) {
368    MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
369
370    // rsWrap can be null because this function is called inside of init.
371    if (rsWrap != null) {
372      addGaugesToMetricsRecordBuilder(mrb)
373        .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
374          rsWrap.getTotalRequestCount())
375        .addCounter(
376          Interns.info(TOTAL_ROW_ACTION_REQUEST_COUNT, TOTAL_ROW_ACTION_REQUEST_COUNT_DESC),
377          rsWrap.getTotalRowActionRequestCount())
378        .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
379          rsWrap.getReadRequestsCount())
380        .addCounter(Interns.info(CP_REQUEST_COUNT, CP_REQUEST_COUNT_DESC),
381          rsWrap.getCpRequestsCount())
382        .addCounter(Interns.info(FILTERED_READ_REQUEST_COUNT, FILTERED_READ_REQUEST_COUNT_DESC),
383          rsWrap.getFilteredReadRequestsCount())
384        .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
385          rsWrap.getWriteRequestsCount())
386        .addCounter(Interns.info(RPC_GET_REQUEST_COUNT, RPC_GET_REQUEST_COUNT_DESC),
387          rsWrap.getRpcGetRequestsCount())
388        .addCounter(Interns.info(RPC_FULL_SCAN_REQUEST_COUNT, RPC_FULL_SCAN_REQUEST_COUNT_DESC),
389          rsWrap.getRpcFullScanRequestsCount())
390        .addCounter(Interns.info(RPC_SCAN_REQUEST_COUNT, RPC_SCAN_REQUEST_COUNT_DESC),
391          rsWrap.getRpcScanRequestsCount())
392        .addCounter(Interns.info(RPC_MULTI_REQUEST_COUNT, RPC_MULTI_REQUEST_COUNT_DESC),
393          rsWrap.getRpcMultiRequestsCount())
394        .addCounter(Interns.info(RPC_MUTATE_REQUEST_COUNT, RPC_MUTATE_REQUEST_COUNT_DESC),
395          rsWrap.getRpcMutateRequestsCount())
396        .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
397          rsWrap.getCheckAndMutateChecksFailed())
398        .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
399          rsWrap.getCheckAndMutateChecksPassed())
400        .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
401          rsWrap.getBlockCacheHitCount())
402        .addCounter(Interns.info(BLOCK_CACHE_PRIMARY_HIT_COUNT, BLOCK_CACHE_PRIMARY_HIT_COUNT_DESC),
403          rsWrap.getBlockCachePrimaryHitCount())
404        .addCounter(Interns.info(BLOCK_CACHE_HIT_CACHING_COUNT, BLOCK_CACHE_HIT_CACHING_COUNT_DESC),
405          rsWrap.getBlockCacheHitCachingCount())
406        .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
407          rsWrap.getBlockCacheMissCount())
408        .addCounter(
409          Interns.info(BLOCK_CACHE_PRIMARY_MISS_COUNT, BLOCK_COUNT_PRIMARY_MISS_COUNT_DESC),
410          rsWrap.getBlockCachePrimaryMissCount())
411        .addCounter(
412          Interns.info(BLOCK_CACHE_MISS_CACHING_COUNT, BLOCK_COUNT_MISS_CACHING_COUNT_DESC),
413          rsWrap.getBlockCacheMissCachingCount())
414        .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
415          rsWrap.getBlockCacheEvictedCount())
416        .addCounter(
417          Interns.info(BLOCK_CACHE_PRIMARY_EVICTION_COUNT, BLOCK_CACHE_PRIMARY_EVICTION_COUNT_DESC),
418          rsWrap.getBlockCachePrimaryEvictedCount())
419        .addCounter(
420          Interns.info(BLOCK_CACHE_FAILED_INSERTION_COUNT, BLOCK_CACHE_FAILED_INSERTION_COUNT_DESC),
421          rsWrap.getBlockCacheFailedInsertions())
422        .addCounter(Interns.info(BLOCK_CACHE_DATA_MISS_COUNT, ""), rsWrap.getDataMissCount())
423        .addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_MISS_COUNT, ""),
424          rsWrap.getLeafIndexMissCount())
425        .addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_MISS_COUNT, ""),
426          rsWrap.getBloomChunkMissCount())
427        .addCounter(Interns.info(BLOCK_CACHE_META_MISS_COUNT, ""), rsWrap.getMetaMissCount())
428        .addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_MISS_COUNT, ""),
429          rsWrap.getRootIndexMissCount())
430        .addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_MISS_COUNT, ""),
431          rsWrap.getIntermediateIndexMissCount())
432        .addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_MISS_COUNT, ""),
433          rsWrap.getFileInfoMissCount())
434        .addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_MISS_COUNT, ""),
435          rsWrap.getGeneralBloomMetaMissCount())
436        .addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT, ""),
437          rsWrap.getDeleteFamilyBloomMissCount())
438        .addCounter(Interns.info(BLOCK_CACHE_TRAILER_MISS_COUNT, ""), rsWrap.getTrailerMissCount())
439        .addCounter(Interns.info(BLOCK_CACHE_DATA_HIT_COUNT, ""), rsWrap.getDataHitCount())
440        .addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_HIT_COUNT, ""),
441          rsWrap.getLeafIndexHitCount())
442        .addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_HIT_COUNT, ""),
443          rsWrap.getBloomChunkHitCount())
444        .addCounter(Interns.info(BLOCK_CACHE_META_HIT_COUNT, ""), rsWrap.getMetaHitCount())
445        .addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_HIT_COUNT, ""),
446          rsWrap.getRootIndexHitCount())
447        .addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_HIT_COUNT, ""),
448          rsWrap.getIntermediateIndexHitCount())
449        .addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_HIT_COUNT, ""), rsWrap.getFileInfoHitCount())
450        .addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT, ""),
451          rsWrap.getGeneralBloomMetaHitCount())
452        .addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
453          rsWrap.getDeleteFamilyBloomHitCount())
454        .addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
455        .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
456          rsWrap.getUpdatesBlockedTime())
457        .addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC), rsWrap.getFlushedCellsCount())
458        .addCounter(Interns.info(COMPACTED_CELLS, COMPACTED_CELLS_DESC),
459          rsWrap.getCompactedCellsCount())
460        .addCounter(Interns.info(MAJOR_COMPACTED_CELLS, MAJOR_COMPACTED_CELLS_DESC),
461          rsWrap.getMajorCompactedCellsCount())
462        .addCounter(Interns.info(FLUSHED_CELLS_SIZE, FLUSHED_CELLS_SIZE_DESC),
463          rsWrap.getFlushedCellsSize())
464        .addCounter(Interns.info(COMPACTED_CELLS_SIZE, COMPACTED_CELLS_SIZE_DESC),
465          rsWrap.getCompactedCellsSize())
466        .addCounter(Interns.info(MAJOR_COMPACTED_CELLS_SIZE, MAJOR_COMPACTED_CELLS_SIZE_DESC),
467          rsWrap.getMajorCompactedCellsSize())
468        .addCounter(
469          Interns.info(CELLS_COUNT_COMPACTED_FROM_MOB, CELLS_COUNT_COMPACTED_FROM_MOB_DESC),
470          rsWrap.getCellsCountCompactedFromMob())
471        .addCounter(Interns.info(CELLS_COUNT_COMPACTED_TO_MOB, CELLS_COUNT_COMPACTED_TO_MOB_DESC),
472          rsWrap.getCellsCountCompactedToMob())
473        .addCounter(Interns.info(CELLS_SIZE_COMPACTED_FROM_MOB, CELLS_SIZE_COMPACTED_FROM_MOB_DESC),
474          rsWrap.getCellsSizeCompactedFromMob())
475        .addCounter(Interns.info(CELLS_SIZE_COMPACTED_TO_MOB, CELLS_SIZE_COMPACTED_TO_MOB_DESC),
476          rsWrap.getCellsSizeCompactedToMob())
477        .addCounter(Interns.info(MOB_FLUSH_COUNT, MOB_FLUSH_COUNT_DESC), rsWrap.getMobFlushCount())
478        .addCounter(Interns.info(MOB_FLUSHED_CELLS_COUNT, MOB_FLUSHED_CELLS_COUNT_DESC),
479          rsWrap.getMobFlushedCellsCount())
480        .addCounter(Interns.info(MOB_FLUSHED_CELLS_SIZE, MOB_FLUSHED_CELLS_SIZE_DESC),
481          rsWrap.getMobFlushedCellsSize())
482        .addCounter(Interns.info(MOB_SCAN_CELLS_COUNT, MOB_SCAN_CELLS_COUNT_DESC),
483          rsWrap.getMobScanCellsCount())
484        .addCounter(Interns.info(MOB_SCAN_CELLS_SIZE, MOB_SCAN_CELLS_SIZE_DESC),
485          rsWrap.getMobScanCellsSize())
486        .addCounter(Interns.info(MOB_FILE_CACHE_ACCESS_COUNT, MOB_FILE_CACHE_ACCESS_COUNT_DESC),
487          rsWrap.getMobFileCacheAccessCount())
488        .addCounter(Interns.info(MOB_FILE_CACHE_MISS_COUNT, MOB_FILE_CACHE_MISS_COUNT_DESC),
489          rsWrap.getMobFileCacheMissCount())
490        .addCounter(Interns.info(MOB_FILE_CACHE_EVICTED_COUNT, MOB_FILE_CACHE_EVICTED_COUNT_DESC),
491          rsWrap.getMobFileCacheEvictedCount())
492        .addCounter(Interns.info(HEDGED_READS, HEDGED_READS_DESC), rsWrap.getHedgedReadOps())
493        .addCounter(Interns.info(HEDGED_READ_WINS, HEDGED_READ_WINS_DESC),
494          rsWrap.getHedgedReadWins())
495        .addCounter(Interns.info(HEDGED_READ_IN_CUR_THREAD, HEDGED_READ_IN_CUR_THREAD_DESC),
496          rsWrap.getHedgedReadOpsInCurThread())
497        .addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
498          rsWrap.getBlockedRequestsCount())
499        .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
500          rsWrap.getZookeeperQuorum())
501        .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
502        .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
503    }
504
505    metricsRegistry.snapshot(mrb, all);
506
507    // source is registered in supers constructor, sometimes called before the whole initialization.
508    if (metricsAdapter != null) {
509      // snapshot MetricRegistry as well
510      metricsAdapter.snapshotAllMetrics(registry, mrb);
511    }
512  }
513
514  private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilder mrb) {
515    return mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
516      .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
517      .addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
518      .addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
519      .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
520      .addGauge(Interns.info(MAX_STOREFILE_COUNT, MAX_STOREFILE_COUNT_DESC),
521        rsWrap.getMaxStoreFiles())
522      .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemStoreSize())
523      .addGauge(Interns.info(MEMSTORE_HEAP_SIZE, MEMSTORE_HEAP_SIZE_DESC),
524        rsWrap.getOnHeapMemStoreSize())
525      .addGauge(Interns.info(MEMSTORE_OFFHEAP_SIZE, MEMSTORE_OFFHEAP_SIZE_DESC),
526        rsWrap.getOffHeapMemStoreSize())
527      .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
528      .addGauge(Interns.info(STOREFILE_SIZE_GROWTH_RATE, STOREFILE_SIZE_GROWTH_RATE_DESC),
529        rsWrap.getStoreFileSizeGrowthRate())
530      .addGauge(Interns.info(MAX_STORE_FILE_AGE, MAX_STORE_FILE_AGE_DESC),
531        rsWrap.getMaxStoreFileAge())
532      .addGauge(Interns.info(MIN_STORE_FILE_AGE, MIN_STORE_FILE_AGE_DESC),
533        rsWrap.getMinStoreFileAge())
534      .addGauge(Interns.info(AVG_STORE_FILE_AGE, AVG_STORE_FILE_AGE_DESC),
535        rsWrap.getAvgStoreFileAge())
536      .addGauge(Interns.info(NUM_REFERENCE_FILES, NUM_REFERENCE_FILES_DESC),
537        rsWrap.getNumReferenceFiles())
538      .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC), rsWrap.getStartCode())
539      .addGauge(Interns.info(AVERAGE_REGION_SIZE, AVERAGE_REGION_SIZE_DESC),
540        rsWrap.getAverageRegionSize())
541      .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
542        rsWrap.getStoreFileIndexSize())
543      .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
544        rsWrap.getTotalStaticIndexSize())
545      .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
546        rsWrap.getTotalStaticBloomSize())
547      .addCounter(Interns.info(BLOOM_FILTER_REQUESTS_COUNT, BLOOM_FILTER_REQUESTS_COUNT_DESC),
548        rsWrap.getBloomFilterRequestsCount())
549      .addCounter(
550        Interns.info(BLOOM_FILTER_NEGATIVE_RESULTS_COUNT, BLOOM_FILTER_NEGATIVE_RESULTS_COUNT_DESC),
551        rsWrap.getBloomFilterNegativeResultsCount())
552      .addCounter(Interns.info(BLOOM_FILTER_ELIGIBLE_REQUESTS_COUNT,
553        BLOOM_FILTER_ELIGIBLE_REQUESTS_COUNT_DESC), rsWrap.getBloomFilterEligibleRequestsCount())
554      .addGauge(Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
555        rsWrap.getNumMutationsWithoutWAL())
556      .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
557        rsWrap.getDataInMemoryWithoutWAL())
558      .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
559        rsWrap.getPercentFileLocal())
560      .addGauge(Interns.info(PERCENT_FILES_LOCAL_SECONDARY_REGIONS,
561        PERCENT_FILES_LOCAL_SECONDARY_REGIONS_DESC), rsWrap.getPercentFileLocalSecondaryRegions())
562      .addGauge(Interns.info(TOTAL_BYTES_READ, TOTAL_BYTES_READ_DESC), rsWrap.getTotalBytesRead())
563      .addGauge(Interns.info(LOCAL_BYTES_READ, LOCAL_BYTES_READ_DESC), rsWrap.getLocalBytesRead())
564      .addGauge(Interns.info(SHORTCIRCUIT_BYTES_READ, SHORTCIRCUIT_BYTES_READ_DESC),
565        rsWrap.getShortCircuitBytesRead())
566      .addGauge(Interns.info(ZEROCOPY_BYTES_READ, ZEROCOPY_BYTES_READ_DESC),
567        rsWrap.getZeroCopyBytesRead())
568      .addGauge(Interns.info(SPLIT_QUEUE_LENGTH, SPLIT_QUEUE_LENGTH_DESC),
569        rsWrap.getSplitQueueSize())
570      .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
571        rsWrap.getCompactionQueueSize())
572      .addGauge(Interns.info(SMALL_COMPACTION_QUEUE_LENGTH, SMALL_COMPACTION_QUEUE_LENGTH_DESC),
573        rsWrap.getSmallCompactionQueueSize())
574      .addGauge(Interns.info(LARGE_COMPACTION_QUEUE_LENGTH, LARGE_COMPACTION_QUEUE_LENGTH_DESC),
575        rsWrap.getLargeCompactionQueueSize())
576      .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
577        rsWrap.getFlushQueueSize())
578      .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
579        rsWrap.getBlockCacheFreeSize())
580      .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
581        rsWrap.getBlockCacheCount())
582      .addGauge(Interns.info(BLOCK_CACHE_DATA_BLOCK_COUNT, BLOCK_CACHE_DATA_BLOCK_COUNT_DESC),
583        rsWrap.getBlockCacheDataBlockCount())
584      .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC), rsWrap.getBlockCacheSize())
585      .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
586        rsWrap.getBlockCacheHitPercent())
587      .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT, BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC),
588        rsWrap.getBlockCacheHitCachingPercent())
589      .addGauge(Interns.info(L1_CACHE_SIZE, L1_CACHE_SIZE_DESC), rsWrap.getL1CacheSize())
590      .addGauge(Interns.info(L1_CACHE_FREE_SIZE, L1_CACHE_FREE_SIZE_DESC),
591        rsWrap.getL1CacheFreeSize())
592      .addGauge(Interns.info(L1_CACHE_COUNT, L1_CACHE_COUNT_DESC), rsWrap.getL1CacheCount())
593      .addCounter(Interns.info(L1_CACHE_EVICTION_COUNT, L1_CACHE_EVICTION_COUNT_DESC),
594        rsWrap.getL1CacheEvictedCount())
595      .addGauge(Interns.info(L1_CACHE_HIT_COUNT, L1_CACHE_HIT_COUNT_DESC),
596        rsWrap.getL1CacheHitCount())
597      .addGauge(Interns.info(L1_CACHE_MISS_COUNT, L1_CACHE_MISS_COUNT_DESC),
598        rsWrap.getL1CacheMissCount())
599      .addGauge(Interns.info(L1_CACHE_HIT_RATIO, L1_CACHE_HIT_RATIO_DESC),
600        rsWrap.getL1CacheHitRatio())
601      .addGauge(Interns.info(L1_CACHE_MISS_RATIO, L1_CACHE_MISS_RATIO_DESC),
602        rsWrap.getL1CacheMissRatio())
603      .addGauge(Interns.info(L2_CACHE_SIZE, L2_CACHE_SIZE_DESC), rsWrap.getL2CacheSize())
604      .addGauge(Interns.info(L2_CACHE_FREE_SIZE, L2_CACHE_FREE_SIZE_DESC),
605        rsWrap.getL2CacheFreeSize())
606      .addGauge(Interns.info(L2_CACHE_COUNT, L2_CACHE_COUNT_DESC), rsWrap.getL2CacheCount())
607      .addCounter(Interns.info(L2_CACHE_EVICTION_COUNT, L2_CACHE_EVICTION_COUNT_DESC),
608        rsWrap.getL2CacheEvictedCount())
609      .addGauge(Interns.info(L2_CACHE_HIT_COUNT, L2_CACHE_HIT_COUNT_DESC),
610        rsWrap.getL2CacheHitCount())
611      .addGauge(Interns.info(L2_CACHE_MISS_COUNT, L2_CACHE_MISS_COUNT_DESC),
612        rsWrap.getL2CacheMissCount())
613      .addGauge(Interns.info(L2_CACHE_HIT_RATIO, L2_CACHE_HIT_RATIO_DESC),
614        rsWrap.getL2CacheHitRatio())
615      .addGauge(Interns.info(L2_CACHE_MISS_RATIO, L2_CACHE_MISS_RATIO_DESC),
616        rsWrap.getL2CacheMissRatio())
617      .addGauge(Interns.info(MOB_FILE_CACHE_COUNT, MOB_FILE_CACHE_COUNT_DESC),
618        rsWrap.getMobFileCacheCount())
619      .addGauge(Interns.info(MOB_FILE_CACHE_HIT_PERCENT, MOB_FILE_CACHE_HIT_PERCENT_DESC),
620        rsWrap.getMobFileCacheHitPercent())
621      .addGauge(Interns.info(READ_REQUEST_RATE_PER_SECOND, READ_REQUEST_RATE_DESC),
622        rsWrap.getReadRequestsRatePerSecond())
623      .addGauge(Interns.info(WRITE_REQUEST_RATE_PER_SECOND, WRITE_REQUEST_RATE_DESC),
624        rsWrap.getWriteRequestsRatePerSecond())
625      .addGauge(
626        Interns.info(BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_BYTES,
627          BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_BYTES_DESC),
628        rsWrap.getByteBuffAllocatorHeapAllocationBytes())
629      .addGauge(
630        Interns.info(BYTE_BUFF_ALLOCATOR_POOL_ALLOCATION_BYTES,
631          BYTE_BUFF_ALLOCATOR_POOL_ALLOCATION_BYTES_DESC),
632        rsWrap.getByteBuffAllocatorPoolAllocationBytes())
633      .addGauge(
634        Interns.info(BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_RATIO,
635          BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_RATIO_DESC),
636        rsWrap.getByteBuffAllocatorHeapAllocRatio())
637      .addGauge(
638        Interns.info(BYTE_BUFF_ALLOCATOR_TOTAL_BUFFER_COUNT,
639          BYTE_BUFF_ALLOCATOR_TOTAL_BUFFER_COUNT_DESC),
640        rsWrap.getByteBuffAllocatorTotalBufferCount())
641      .addGauge(Interns.info(BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT,
642        BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT_DESC), rsWrap.getByteBuffAllocatorUsedBufferCount())
643      .addGauge(Interns.info(ACTIVE_SCANNERS, ACTIVE_SCANNERS_DESC), rsWrap.getActiveScanners());
644  }
645
646  @Override
647  public void incInfoThresholdExceeded(int count) {
648    infoPauseThresholdExceeded.incr(count);
649  }
650
651  @Override
652  public void incWarnThresholdExceeded(int count) {
653    warnPauseThresholdExceeded.incr(count);
654  }
655
656  @Override
657  public void updatePauseTimeWithGc(long t) {
658    pausesWithGc.add(t);
659  }
660
661  @Override
662  public void updatePauseTimeWithoutGc(long t) {
663    pausesWithoutGc.add(t);
664  }
665
666  @Override
667  public void updateDeleteBatch(long t) {
668    deleteBatchHisto.add(t);
669  }
670
671  @Override
672  public void updateCheckAndDelete(long t) {
673    checkAndDeleteHisto.add(t);
674  }
675
676  @Override
677  public void updateCheckAndPut(long t) {
678    checkAndPutHisto.add(t);
679  }
680
681  @Override
682  public void updateCheckAndMutate(long time, long blockBytesScanned) {
683    checkAndMutateHisto.add(time);
684    if (blockBytesScanned > 0) {
685      blockBytesScannedCount.incr(blockBytesScanned);
686      checkAndMutateBlockBytesScanned.add(blockBytesScanned);
687    }
688  }
689
690  @Override
691  public void updatePutBatch(long t) {
692    putBatchHisto.add(t);
693  }
694}