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.metrics2.MetricHistogram; 022import org.apache.hadoop.metrics2.lib.MutableFastCounter; 023import org.apache.hadoop.metrics2.lib.MutableGaugeLong; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Hadoop2 implementation of MetricsHeapMemoryManagerSource. Implements BaseSource through 028 * BaseSourceImpl, following the pattern 029 */ 030@InterfaceAudience.Private 031public class MetricsHeapMemoryManagerSourceImpl extends BaseSourceImpl 032 implements MetricsHeapMemoryManagerSource { 033 034 private final MetricHistogram blockedFlushHistogram; 035 private final MetricHistogram unblockedFlushHistogram; 036 private final MetricHistogram incMemStoreSizeHistogram; 037 private final MetricHistogram decMemStoreSizeHistogram; 038 private final MetricHistogram incBlockCacheSizeHistogram; 039 private final MetricHistogram decBlockCacheSizeHistogram; 040 041 private final MutableGaugeLong blockedFlushGauge; 042 private final MutableGaugeLong unblockedFlushGauge; 043 private final MutableGaugeLong memStoreSizeGauge; 044 private final MutableGaugeLong blockCacheSizeGauge; 045 046 private final MutableFastCounter doNothingCounter; 047 private final MutableFastCounter aboveHeapOccupancyLowWatermarkCounter; 048 049 public MetricsHeapMemoryManagerSourceImpl() { 050 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); 051 } 052 053 public MetricsHeapMemoryManagerSourceImpl(String metricsName, String metricsDescription, 054 String metricsContext, String metricsJmxContext) { 055 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 056 057 // Histograms 058 blockedFlushHistogram = 059 getMetricsRegistry().newSizeHistogram(BLOCKED_FLUSH_NAME, BLOCKED_FLUSH_DESC); 060 unblockedFlushHistogram = 061 getMetricsRegistry().newSizeHistogram(UNBLOCKED_FLUSH_NAME, UNBLOCKED_FLUSH_DESC); 062 incMemStoreSizeHistogram = 063 getMetricsRegistry().newSizeHistogram(INC_MEMSTORE_TUNING_NAME, INC_MEMSTORE_TUNING_DESC); 064 decMemStoreSizeHistogram = 065 getMetricsRegistry().newSizeHistogram(DEC_MEMSTORE_TUNING_NAME, DEC_MEMSTORE_TUNING_DESC); 066 incBlockCacheSizeHistogram = 067 getMetricsRegistry().newSizeHistogram(INC_BLOCKCACHE_TUNING_NAME, INC_BLOCKCACHE_TUNING_DESC); 068 decBlockCacheSizeHistogram = 069 getMetricsRegistry().newSizeHistogram(DEC_BLOCKCACHE_TUNING_NAME, DEC_BLOCKCACHE_TUNING_DESC); 070 071 // Gauges 072 blockedFlushGauge = 073 getMetricsRegistry().newGauge(BLOCKED_FLUSH_GAUGE_NAME, BLOCKED_FLUSH_GAUGE_DESC, 0L); 074 unblockedFlushGauge = 075 getMetricsRegistry().newGauge(UNBLOCKED_FLUSH_GAUGE_NAME, UNBLOCKED_FLUSH_GAUGE_DESC, 0L); 076 memStoreSizeGauge = 077 getMetricsRegistry().newGauge(MEMSTORE_SIZE_GAUGE_NAME, MEMSTORE_SIZE_GAUGE_DESC, 0L); 078 blockCacheSizeGauge = 079 getMetricsRegistry().newGauge(BLOCKCACHE_SIZE_GAUGE_NAME, BLOCKCACHE_SIZE_GAUGE_DESC, 0L); 080 081 // Counters 082 doNothingCounter = 083 getMetricsRegistry().newCounter(DO_NOTHING_COUNTER_NAME, DO_NOTHING_COUNTER_DESC, 0L); 084 aboveHeapOccupancyLowWatermarkCounter = getMetricsRegistry() 085 .newCounter(ABOVE_HEAP_LOW_WATERMARK_COUNTER_NAME, ABOVE_HEAP_LOW_WATERMARK_COUNTER_DESC, 0L); 086 } 087 088 @Override 089 public void updateBlockedFlushCount(long blockedFlushCount) { 090 if (blockedFlushCount > 0) { 091 blockedFlushHistogram.add(blockedFlushCount); 092 blockedFlushGauge.set(blockedFlushCount); 093 } 094 } 095 096 @Override 097 public void updateUnblockedFlushCount(long unblockedFlushCount) { 098 if (unblockedFlushCount > 0) { 099 unblockedFlushHistogram.add(unblockedFlushCount); 100 unblockedFlushGauge.set(unblockedFlushCount); 101 } 102 } 103 104 @Override 105 public void setCurBlockCacheSizeGauge(long blockcacheSize) { 106 blockCacheSizeGauge.set(blockcacheSize); 107 } 108 109 @Override 110 public void setCurMemStoreSizeGauge(long memstoreSize) { 111 memStoreSizeGauge.set(memstoreSize); 112 } 113 114 @Override 115 public void updateMemStoreDeltaSizeHistogram(int memStoreDeltaSize) { 116 if (memStoreDeltaSize >= 0) { 117 incMemStoreSizeHistogram.add(memStoreDeltaSize); 118 } else if (memStoreDeltaSize < 0) { 119 decMemStoreSizeHistogram.add(-memStoreDeltaSize); 120 } 121 } 122 123 @Override 124 public void updateBlockCacheDeltaSizeHistogram(int blockCacheDeltaSize) { 125 if (blockCacheDeltaSize >= 0) { 126 incBlockCacheSizeHistogram.add(blockCacheDeltaSize); 127 } else if (blockCacheDeltaSize < 0) { 128 decBlockCacheSizeHistogram.add(-blockCacheDeltaSize); 129 } 130 } 131 132 @Override 133 public void increaseTunerDoNothingCounter() { 134 doNothingCounter.incr(); 135 } 136 137 @Override 138 public void increaseAboveHeapOccupancyLowWatermarkCounter() { 139 aboveHeapOccupancyLowWatermarkCounter.incr(); 140 } 141}