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