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