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(CP_REQUEST_COUNT, CP_REQUEST_COUNT_DESC),
352          rsWrap.getCpRequestsCount())
353        .addCounter(Interns.info(FILTERED_READ_REQUEST_COUNT, FILTERED_READ_REQUEST_COUNT_DESC),
354          rsWrap.getFilteredReadRequestsCount())
355        .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
356          rsWrap.getWriteRequestsCount())
357        .addCounter(Interns.info(RPC_GET_REQUEST_COUNT, RPC_GET_REQUEST_COUNT_DESC),
358          rsWrap.getRpcGetRequestsCount())
359        .addCounter(Interns.info(RPC_FULL_SCAN_REQUEST_COUNT, RPC_FULL_SCAN_REQUEST_COUNT_DESC),
360          rsWrap.getRpcFullScanRequestsCount())
361        .addCounter(Interns.info(RPC_SCAN_REQUEST_COUNT, RPC_SCAN_REQUEST_COUNT_DESC),
362          rsWrap.getRpcScanRequestsCount())
363        .addCounter(Interns.info(RPC_MULTI_REQUEST_COUNT, RPC_MULTI_REQUEST_COUNT_DESC),
364          rsWrap.getRpcMultiRequestsCount())
365        .addCounter(Interns.info(RPC_MUTATE_REQUEST_COUNT, RPC_MUTATE_REQUEST_COUNT_DESC),
366          rsWrap.getRpcMutateRequestsCount())
367        .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
368          rsWrap.getCheckAndMutateChecksFailed())
369        .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
370          rsWrap.getCheckAndMutateChecksPassed())
371        .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
372          rsWrap.getBlockCacheHitCount())
373        .addCounter(Interns.info(BLOCK_CACHE_PRIMARY_HIT_COUNT, BLOCK_CACHE_PRIMARY_HIT_COUNT_DESC),
374          rsWrap.getBlockCachePrimaryHitCount())
375        .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
376          rsWrap.getBlockCacheMissCount())
377        .addCounter(
378          Interns.info(BLOCK_CACHE_PRIMARY_MISS_COUNT, BLOCK_COUNT_PRIMARY_MISS_COUNT_DESC),
379          rsWrap.getBlockCachePrimaryMissCount())
380        .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
381          rsWrap.getBlockCacheEvictedCount())
382        .addCounter(
383          Interns.info(BLOCK_CACHE_PRIMARY_EVICTION_COUNT, BLOCK_CACHE_PRIMARY_EVICTION_COUNT_DESC),
384          rsWrap.getBlockCachePrimaryEvictedCount())
385        .addCounter(
386          Interns.info(BLOCK_CACHE_FAILED_INSERTION_COUNT, BLOCK_CACHE_FAILED_INSERTION_COUNT_DESC),
387          rsWrap.getBlockCacheFailedInsertions())
388        .addCounter(Interns.info(BLOCK_CACHE_DATA_MISS_COUNT, ""), rsWrap.getDataMissCount())
389        .addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_MISS_COUNT, ""),
390          rsWrap.getLeafIndexMissCount())
391        .addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_MISS_COUNT, ""),
392          rsWrap.getBloomChunkMissCount())
393        .addCounter(Interns.info(BLOCK_CACHE_META_MISS_COUNT, ""), rsWrap.getMetaMissCount())
394        .addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_MISS_COUNT, ""),
395          rsWrap.getRootIndexMissCount())
396        .addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_MISS_COUNT, ""),
397          rsWrap.getIntermediateIndexMissCount())
398        .addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_MISS_COUNT, ""),
399          rsWrap.getFileInfoMissCount())
400        .addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_MISS_COUNT, ""),
401          rsWrap.getGeneralBloomMetaMissCount())
402        .addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT, ""),
403          rsWrap.getDeleteFamilyBloomMissCount())
404        .addCounter(Interns.info(BLOCK_CACHE_TRAILER_MISS_COUNT, ""), rsWrap.getTrailerMissCount())
405        .addCounter(Interns.info(BLOCK_CACHE_DATA_HIT_COUNT, ""), rsWrap.getDataHitCount())
406        .addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_HIT_COUNT, ""),
407          rsWrap.getLeafIndexHitCount())
408        .addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_HIT_COUNT, ""),
409          rsWrap.getBloomChunkHitCount())
410        .addCounter(Interns.info(BLOCK_CACHE_META_HIT_COUNT, ""), rsWrap.getMetaHitCount())
411        .addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_HIT_COUNT, ""),
412          rsWrap.getRootIndexHitCount())
413        .addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_HIT_COUNT, ""),
414          rsWrap.getIntermediateIndexHitCount())
415        .addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_HIT_COUNT, ""), rsWrap.getFileInfoHitCount())
416        .addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT, ""),
417          rsWrap.getGeneralBloomMetaHitCount())
418        .addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
419          rsWrap.getDeleteFamilyBloomHitCount())
420        .addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
421        .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
422          rsWrap.getUpdatesBlockedTime())
423        .addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC), rsWrap.getFlushedCellsCount())
424        .addCounter(Interns.info(COMPACTED_CELLS, COMPACTED_CELLS_DESC),
425          rsWrap.getCompactedCellsCount())
426        .addCounter(Interns.info(MAJOR_COMPACTED_CELLS, MAJOR_COMPACTED_CELLS_DESC),
427          rsWrap.getMajorCompactedCellsCount())
428        .addCounter(Interns.info(FLUSHED_CELLS_SIZE, FLUSHED_CELLS_SIZE_DESC),
429          rsWrap.getFlushedCellsSize())
430        .addCounter(Interns.info(COMPACTED_CELLS_SIZE, COMPACTED_CELLS_SIZE_DESC),
431          rsWrap.getCompactedCellsSize())
432        .addCounter(Interns.info(MAJOR_COMPACTED_CELLS_SIZE, MAJOR_COMPACTED_CELLS_SIZE_DESC),
433          rsWrap.getMajorCompactedCellsSize())
434        .addCounter(
435          Interns.info(CELLS_COUNT_COMPACTED_FROM_MOB, CELLS_COUNT_COMPACTED_FROM_MOB_DESC),
436          rsWrap.getCellsCountCompactedFromMob())
437        .addCounter(Interns.info(CELLS_COUNT_COMPACTED_TO_MOB, CELLS_COUNT_COMPACTED_TO_MOB_DESC),
438          rsWrap.getCellsCountCompactedToMob())
439        .addCounter(Interns.info(CELLS_SIZE_COMPACTED_FROM_MOB, CELLS_SIZE_COMPACTED_FROM_MOB_DESC),
440          rsWrap.getCellsSizeCompactedFromMob())
441        .addCounter(Interns.info(CELLS_SIZE_COMPACTED_TO_MOB, CELLS_SIZE_COMPACTED_TO_MOB_DESC),
442          rsWrap.getCellsSizeCompactedToMob())
443        .addCounter(Interns.info(MOB_FLUSH_COUNT, MOB_FLUSH_COUNT_DESC), rsWrap.getMobFlushCount())
444        .addCounter(Interns.info(MOB_FLUSHED_CELLS_COUNT, MOB_FLUSHED_CELLS_COUNT_DESC),
445          rsWrap.getMobFlushedCellsCount())
446        .addCounter(Interns.info(MOB_FLUSHED_CELLS_SIZE, MOB_FLUSHED_CELLS_SIZE_DESC),
447          rsWrap.getMobFlushedCellsSize())
448        .addCounter(Interns.info(MOB_SCAN_CELLS_COUNT, MOB_SCAN_CELLS_COUNT_DESC),
449          rsWrap.getMobScanCellsCount())
450        .addCounter(Interns.info(MOB_SCAN_CELLS_SIZE, MOB_SCAN_CELLS_SIZE_DESC),
451          rsWrap.getMobScanCellsSize())
452        .addCounter(Interns.info(MOB_FILE_CACHE_ACCESS_COUNT, MOB_FILE_CACHE_ACCESS_COUNT_DESC),
453          rsWrap.getMobFileCacheAccessCount())
454        .addCounter(Interns.info(MOB_FILE_CACHE_MISS_COUNT, MOB_FILE_CACHE_MISS_COUNT_DESC),
455          rsWrap.getMobFileCacheMissCount())
456        .addCounter(Interns.info(MOB_FILE_CACHE_EVICTED_COUNT, MOB_FILE_CACHE_EVICTED_COUNT_DESC),
457          rsWrap.getMobFileCacheEvictedCount())
458        .addCounter(Interns.info(HEDGED_READS, HEDGED_READS_DESC), rsWrap.getHedgedReadOps())
459        .addCounter(Interns.info(HEDGED_READ_WINS, HEDGED_READ_WINS_DESC),
460          rsWrap.getHedgedReadWins())
461        .addCounter(Interns.info(HEDGED_READ_IN_CUR_THREAD, HEDGED_READ_IN_CUR_THREAD_DESC),
462          rsWrap.getHedgedReadOpsInCurThread())
463        .addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
464          rsWrap.getBlockedRequestsCount())
465        .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
466          rsWrap.getZookeeperQuorum())
467        .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
468        .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
469    }
470
471    metricsRegistry.snapshot(mrb, all);
472
473    // source is registered in supers constructor, sometimes called before the whole initialization.
474    if (metricsAdapter != null) {
475      // snapshot MetricRegistry as well
476      metricsAdapter.snapshotAllMetrics(registry, mrb);
477    }
478  }
479
480  private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilder mrb) {
481    return mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
482      .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
483      .addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
484      .addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
485      .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
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(STOREFILE_SIZE_GROWTH_RATE, STOREFILE_SIZE_GROWTH_RATE_DESC),
489        rsWrap.getStoreFileSizeGrowthRate())
490      .addGauge(Interns.info(MAX_STORE_FILE_AGE, MAX_STORE_FILE_AGE_DESC),
491        rsWrap.getMaxStoreFileAge())
492      .addGauge(Interns.info(MIN_STORE_FILE_AGE, MIN_STORE_FILE_AGE_DESC),
493        rsWrap.getMinStoreFileAge())
494      .addGauge(Interns.info(AVG_STORE_FILE_AGE, AVG_STORE_FILE_AGE_DESC),
495        rsWrap.getAvgStoreFileAge())
496      .addGauge(Interns.info(NUM_REFERENCE_FILES, NUM_REFERENCE_FILES_DESC),
497        rsWrap.getNumReferenceFiles())
498      .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC), rsWrap.getStartCode())
499      .addGauge(Interns.info(AVERAGE_REGION_SIZE, AVERAGE_REGION_SIZE_DESC),
500        rsWrap.getAverageRegionSize())
501      .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
502        rsWrap.getStoreFileIndexSize())
503      .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
504        rsWrap.getTotalStaticIndexSize())
505      .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
506        rsWrap.getTotalStaticBloomSize())
507      .addGauge(Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
508        rsWrap.getNumMutationsWithoutWAL())
509      .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
510        rsWrap.getDataInMemoryWithoutWAL())
511      .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
512        rsWrap.getPercentFileLocal())
513      .addGauge(Interns.info(PERCENT_FILES_LOCAL_SECONDARY_REGIONS,
514        PERCENT_FILES_LOCAL_SECONDARY_REGIONS_DESC), rsWrap.getPercentFileLocalSecondaryRegions())
515      .addGauge(Interns.info(TOTAL_BYTES_READ, TOTAL_BYTES_READ_DESC), rsWrap.getTotalBytesRead())
516      .addGauge(Interns.info(LOCAL_BYTES_READ, LOCAL_BYTES_READ_DESC), rsWrap.getLocalBytesRead())
517      .addGauge(Interns.info(SHORTCIRCUIT_BYTES_READ, SHORTCIRCUIT_BYTES_READ_DESC),
518        rsWrap.getShortCircuitBytesRead())
519      .addGauge(Interns.info(ZEROCOPY_BYTES_READ, ZEROCOPY_BYTES_READ_DESC),
520        rsWrap.getZeroCopyBytesRead())
521      .addGauge(Interns.info(SPLIT_QUEUE_LENGTH, SPLIT_QUEUE_LENGTH_DESC),
522        rsWrap.getSplitQueueSize())
523      .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
524        rsWrap.getCompactionQueueSize())
525      .addGauge(Interns.info(SMALL_COMPACTION_QUEUE_LENGTH, SMALL_COMPACTION_QUEUE_LENGTH_DESC),
526        rsWrap.getSmallCompactionQueueSize())
527      .addGauge(Interns.info(LARGE_COMPACTION_QUEUE_LENGTH, LARGE_COMPACTION_QUEUE_LENGTH_DESC),
528        rsWrap.getLargeCompactionQueueSize())
529      .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
530        rsWrap.getFlushQueueSize())
531      .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
532        rsWrap.getBlockCacheFreeSize())
533      .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
534        rsWrap.getBlockCacheCount())
535      .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC), rsWrap.getBlockCacheSize())
536      .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
537        rsWrap.getBlockCacheHitPercent())
538      .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT, BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC),
539        rsWrap.getBlockCacheHitCachingPercent())
540      .addGauge(Interns.info(L1_CACHE_HIT_COUNT, L1_CACHE_HIT_COUNT_DESC),
541        rsWrap.getL1CacheHitCount())
542      .addGauge(Interns.info(L1_CACHE_MISS_COUNT, L1_CACHE_MISS_COUNT_DESC),
543        rsWrap.getL1CacheMissCount())
544      .addGauge(Interns.info(L1_CACHE_HIT_RATIO, L1_CACHE_HIT_RATIO_DESC),
545        rsWrap.getL1CacheHitRatio())
546      .addGauge(Interns.info(L1_CACHE_MISS_RATIO, L1_CACHE_MISS_RATIO_DESC),
547        rsWrap.getL1CacheMissRatio())
548      .addGauge(Interns.info(L2_CACHE_HIT_COUNT, L2_CACHE_HIT_COUNT_DESC),
549        rsWrap.getL2CacheHitCount())
550      .addGauge(Interns.info(L2_CACHE_MISS_COUNT, L2_CACHE_MISS_COUNT_DESC),
551        rsWrap.getL2CacheMissCount())
552      .addGauge(Interns.info(L2_CACHE_HIT_RATIO, L2_CACHE_HIT_RATIO_DESC),
553        rsWrap.getL2CacheHitRatio())
554      .addGauge(Interns.info(L2_CACHE_MISS_RATIO, L2_CACHE_MISS_RATIO_DESC),
555        rsWrap.getL2CacheMissRatio())
556      .addGauge(Interns.info(MOB_FILE_CACHE_COUNT, MOB_FILE_CACHE_COUNT_DESC),
557        rsWrap.getMobFileCacheCount())
558      .addGauge(Interns.info(MOB_FILE_CACHE_HIT_PERCENT, MOB_FILE_CACHE_HIT_PERCENT_DESC),
559        rsWrap.getMobFileCacheHitPercent())
560      .addGauge(Interns.info(READ_REQUEST_RATE_PER_SECOND, READ_REQUEST_RATE_DESC),
561        rsWrap.getReadRequestsRatePerSecond())
562      .addGauge(Interns.info(WRITE_REQUEST_RATE_PER_SECOND, WRITE_REQUEST_RATE_DESC),
563        rsWrap.getWriteRequestsRatePerSecond())
564      .addGauge(
565        Interns.info(BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_BYTES,
566          BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_BYTES_DESC),
567        rsWrap.getByteBuffAllocatorHeapAllocationBytes())
568      .addGauge(
569        Interns.info(BYTE_BUFF_ALLOCATOR_POOL_ALLOCATION_BYTES,
570          BYTE_BUFF_ALLOCATOR_POOL_ALLOCATION_BYTES_DESC),
571        rsWrap.getByteBuffAllocatorPoolAllocationBytes())
572      .addGauge(
573        Interns.info(BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_RATIO,
574          BYTE_BUFF_ALLOCATOR_HEAP_ALLOCATION_RATIO_DESC),
575        rsWrap.getByteBuffAllocatorHeapAllocRatio())
576      .addGauge(
577        Interns.info(BYTE_BUFF_ALLOCATOR_TOTAL_BUFFER_COUNT,
578          BYTE_BUFF_ALLOCATOR_TOTAL_BUFFER_COUNT_DESC),
579        rsWrap.getByteBuffAllocatorTotalBufferCount())
580      .addGauge(Interns.info(BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT,
581        BYTE_BUFF_ALLOCATOR_USED_BUFFER_COUNT_DESC), rsWrap.getByteBuffAllocatorUsedBufferCount())
582      .addGauge(Interns.info(ACTIVE_SCANNERS, ACTIVE_SCANNERS_DESC), rsWrap.getActiveScanners());
583  }
584
585  @Override
586  public void incInfoThresholdExceeded(int count) {
587    infoPauseThresholdExceeded.incr(count);
588  }
589
590  @Override
591  public void incWarnThresholdExceeded(int count) {
592    warnPauseThresholdExceeded.incr(count);
593  }
594
595  @Override
596  public void updatePauseTimeWithGc(long t) {
597    pausesWithGc.add(t);
598  }
599
600  @Override
601  public void updatePauseTimeWithoutGc(long t) {
602    pausesWithoutGc.add(t);
603  }
604
605  @Override
606  public void updateDeleteBatch(long t) {
607    deleteBatchHisto.add(t);
608  }
609
610  @Override
611  public void updateCheckAndDelete(long t) {
612    checkAndDeleteHisto.add(t);
613  }
614
615  @Override
616  public void updateCheckAndPut(long t) {
617    checkAndPutHisto.add(t);
618  }
619
620  @Override
621  public void updateCheckAndMutate(long t) {
622    checkAndMutateHisto.add(t);
623  }
624
625  @Override
626  public void updatePutBatch(long t) {
627    putBatchHisto.add(t);
628  }
629}