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 memStoreOnHeapSizeGauge; 045 private final MutableGaugeLong memStoreOffHeapSizeGauge; 046 private final MutableGaugeLong blockCacheSizeGauge; 047 048 private final MutableFastCounter doNothingCounter; 049 private final MutableFastCounter aboveHeapOccupancyLowWatermarkCounter; 050 051 public MetricsHeapMemoryManagerSourceImpl() { 052 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); 053 } 054 055 public MetricsHeapMemoryManagerSourceImpl(String metricsName, String metricsDescription, 056 String metricsContext, String metricsJmxContext) { 057 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 058 059 // Histograms 060 blockedFlushHistogram = 061 getMetricsRegistry().newSizeHistogram(BLOCKED_FLUSH_NAME, BLOCKED_FLUSH_DESC); 062 unblockedFlushHistogram = 063 getMetricsRegistry().newSizeHistogram(UNBLOCKED_FLUSH_NAME, UNBLOCKED_FLUSH_DESC); 064 incMemStoreSizeHistogram = 065 getMetricsRegistry().newSizeHistogram(INC_MEMSTORE_TUNING_NAME, INC_MEMSTORE_TUNING_DESC); 066 decMemStoreSizeHistogram = 067 getMetricsRegistry().newSizeHistogram(DEC_MEMSTORE_TUNING_NAME, DEC_MEMSTORE_TUNING_DESC); 068 incBlockCacheSizeHistogram = 069 getMetricsRegistry().newSizeHistogram(INC_BLOCKCACHE_TUNING_NAME, INC_BLOCKCACHE_TUNING_DESC); 070 decBlockCacheSizeHistogram = 071 getMetricsRegistry().newSizeHistogram(DEC_BLOCKCACHE_TUNING_NAME, DEC_BLOCKCACHE_TUNING_DESC); 072 073 // Gauges 074 blockedFlushGauge = 075 getMetricsRegistry().newGauge(BLOCKED_FLUSH_GAUGE_NAME, BLOCKED_FLUSH_GAUGE_DESC, 0L); 076 unblockedFlushGauge = 077 getMetricsRegistry().newGauge(UNBLOCKED_FLUSH_GAUGE_NAME, UNBLOCKED_FLUSH_GAUGE_DESC, 0L); 078 memStoreSizeGauge = 079 getMetricsRegistry().newGauge(MEMSTORE_SIZE_GAUGE_NAME, MEMSTORE_SIZE_GAUGE_DESC, 0L); 080 memStoreOnHeapSizeGauge = getMetricsRegistry().newGauge(MEMSTORE_ONHEAP_SIZE_GAUGE_NAME, 081 MEMSTORE_ONHEAP_SIZE_GAUGE_DESC, 0L); 082 memStoreOffHeapSizeGauge = getMetricsRegistry().newGauge(MEMSTORE_OFFHEAP_SIZE_GAUGE_NAME, 083 MEMSTORE_OFFHEAP_SIZE_GAUGE_DESC, 0L); 084 blockCacheSizeGauge = 085 getMetricsRegistry().newGauge(BLOCKCACHE_SIZE_GAUGE_NAME, BLOCKCACHE_SIZE_GAUGE_DESC, 0L); 086 087 // Counters 088 doNothingCounter = 089 getMetricsRegistry().newCounter(DO_NOTHING_COUNTER_NAME, DO_NOTHING_COUNTER_DESC, 0L); 090 aboveHeapOccupancyLowWatermarkCounter = getMetricsRegistry() 091 .newCounter(ABOVE_HEAP_LOW_WATERMARK_COUNTER_NAME, ABOVE_HEAP_LOW_WATERMARK_COUNTER_DESC, 0L); 092 } 093 094 @Override 095 public void updateBlockedFlushCount(long blockedFlushCount) { 096 if (blockedFlushCount > 0) { 097 blockedFlushHistogram.add(blockedFlushCount); 098 blockedFlushGauge.set(blockedFlushCount); 099 } 100 } 101 102 @Override 103 public void updateUnblockedFlushCount(long unblockedFlushCount) { 104 if (unblockedFlushCount > 0) { 105 unblockedFlushHistogram.add(unblockedFlushCount); 106 unblockedFlushGauge.set(unblockedFlushCount); 107 } 108 } 109 110 @Override 111 public void setCurBlockCacheSizeGauge(long blockcacheSize) { 112 blockCacheSizeGauge.set(blockcacheSize); 113 } 114 115 @Override 116 public void setCurMemStoreSizeGauge(long memstoreSize) { 117 memStoreSizeGauge.set(memstoreSize); 118 } 119 120 @Override 121 public void setCurMemStoreOnHeapSizeGauge(long memstoreOnHeapSize) { 122 memStoreOnHeapSizeGauge.set(memstoreOnHeapSize); 123 } 124 125 @Override 126 public void setCurMemStoreOffHeapSizeGauge(long memstoreOffHeapSize) { 127 memStoreOffHeapSizeGauge.set(memstoreOffHeapSize); 128 } 129 130 @Override 131 public void updateMemStoreDeltaSizeHistogram(int memStoreDeltaSize) { 132 if (memStoreDeltaSize >= 0) { 133 incMemStoreSizeHistogram.add(memStoreDeltaSize); 134 } else if (memStoreDeltaSize < 0) { 135 decMemStoreSizeHistogram.add(-memStoreDeltaSize); 136 } 137 } 138 139 @Override 140 public void updateBlockCacheDeltaSizeHistogram(int blockCacheDeltaSize) { 141 if (blockCacheDeltaSize >= 0) { 142 incBlockCacheSizeHistogram.add(blockCacheDeltaSize); 143 } else if (blockCacheDeltaSize < 0) { 144 decBlockCacheSizeHistogram.add(-blockCacheDeltaSize); 145 } 146 } 147 148 @Override 149 public void increaseTunerDoNothingCounter() { 150 doNothingCounter.incr(); 151 } 152 153 @Override 154 public void increaseAboveHeapOccupancyLowWatermarkCounter() { 155 aboveHeapOccupancyLowWatermarkCounter.incr(); 156 } 157}