int storefiles = 0;
long memstoreSize = 0;
int readRequestsCount = 0;
int writeRequestsCount = 0;
long storefileIndexSize = 0;
HDFSBlocksDistribution hdfsBlocksDistribution =
new HDFSBlocksDistribution();
long totalStaticIndexSize = 0;
long totalStaticBloomSize = 0;
long numPutsWithoutWAL = 0;
long dataInMemoryWithoutWAL = 0;
long updatesBlockedMs = 0;
// Note that this is a map of Doubles instead of Longs. This is because we
// do effective integer division, which would perhaps truncate more than it
// should because we do it only on one part of our sum at a time. Rather
// than dividing at the end, where it is difficult to know the proper
// factor, everything is exact then truncated.
final Map<String, MutableDouble> tempVals =
new HashMap<String, MutableDouble>();
for (Map.Entry<String, HRegion> e : this.onlineRegions.entrySet()) {
HRegion r = e.getValue();
memstoreSize += r.memstoreSize.get();
numPutsWithoutWAL += r.numPutsWithoutWAL.get();
dataInMemoryWithoutWAL += r.dataInMemoryWithoutWAL.get();
readRequestsCount += r.readRequestsCount.get();
writeRequestsCount += r.writeRequestsCount.get();
updatesBlockedMs += r.updatesBlockedMs.get();
synchronized (r.stores) {
stores += r.stores.size();
for (Map.Entry<byte[], Store> ee : r.stores.entrySet()) {
final Store store = ee.getValue();
final SchemaMetrics schemaMetrics = store.getSchemaMetrics();
{
long tmpStorefiles = store.getStorefilesCount();
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.STORE_FILE_COUNT, tmpStorefiles);
storefiles += tmpStorefiles;
}
{
long tmpStorefileIndexSize = store.getStorefilesIndexSize();
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.STORE_FILE_INDEX_SIZE,
(long) (tmpStorefileIndexSize / (1024.0 * 1024)));
storefileIndexSize += tmpStorefileIndexSize;
}
{
long tmpStorefilesSize = store.getStorefilesSize();
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.STORE_FILE_SIZE_MB,
(long) (tmpStorefilesSize / (1024.0 * 1024)));
}
{
long tmpStaticBloomSize = store.getTotalStaticBloomSize();
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.STATIC_BLOOM_SIZE_KB,
(long) (tmpStaticBloomSize / 1024.0));
totalStaticBloomSize += tmpStaticBloomSize;
}
{
long tmpStaticIndexSize = store.getTotalStaticIndexSize();
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.STATIC_INDEX_SIZE_KB,
(long) (tmpStaticIndexSize / 1024.0));
totalStaticIndexSize += tmpStaticIndexSize;
}
schemaMetrics.accumulateStoreMetric(tempVals,
StoreMetricType.MEMSTORE_SIZE_MB,
(long) (store.getMemStoreSize() / (1024.0 * 1024)));
}
}
hdfsBlocksDistribution.add(r.getHDFSBlocksDistribution());
}
for (Entry<String, MutableDouble> e : tempVals.entrySet()) {
RegionMetricsStorage.setNumericMetric(e.getKey(), e.getValue().longValue());
}
this.metrics.stores.set(stores);
this.metrics.storefiles.set(storefiles);
this.metrics.hlogFileCount.set(this.hlog.getNumLogFiles());
this.metrics.hlogFileSizeMB.set(this.hlog.getNumLogFileSize() /(1024 * 1024));
this.metrics.memstoreSizeMB.set((int) (memstoreSize / (1024 * 1024)));
this.metrics.mbInMemoryWithoutWAL.set((int) (dataInMemoryWithoutWAL / (1024 * 1024)));
this.metrics.numPutsWithoutWAL.set(numPutsWithoutWAL);
this.metrics.storefileIndexSizeMB.set(
(int) (storefileIndexSize / (1024 * 1024)));
this.metrics.rootIndexSizeKB.set(
(int) (storefileIndexSize / 1024));
this.metrics.totalStaticIndexSizeKB.set(
(int) (totalStaticIndexSize / 1024));
this.metrics.totalStaticBloomSizeKB.set(
(int) (totalStaticBloomSize / 1024));
this.metrics.readRequestsCount.set(readRequestsCount);
this.metrics.writeRequestsCount.set(writeRequestsCount);
this.metrics.compactionQueueSize.set(compactSplitThread
.getCompactionQueueSize());
this.metrics.flushQueueSize.set(cacheFlusher
.getFlushQueueSize());
this.metrics.updatesBlockedSeconds.set(updatesBlockedMs/1000);
final long updatesBlockedMsHigherWater = cacheFlusher.getUpdatesBlockedMsHighWater().get();
this.metrics.updatesBlockedSecondsHighWater.set(updatesBlockedMsHigherWater/1000);
BlockCache blockCache = cacheConfig.getBlockCache();
if (blockCache != null) {
this.metrics.blockCacheCount.set(blockCache.size());
this.metrics.blockCacheFree.set(blockCache.getFreeSize());
this.metrics.blockCacheSize.set(blockCache.getCurrentSize());
CacheStats cacheStats = blockCache.getStats();
this.metrics.blockCacheHitCount.set(cacheStats.getHitCount());
this.metrics.blockCacheMissCount.set(cacheStats.getMissCount());
this.metrics.blockCacheEvictedCount.set(blockCache.getEvictedCount());
double ratio = blockCache.getStats().getHitRatio();
int percent = (int) (ratio * 100);
this.metrics.blockCacheHitRatio.set(percent);
ratio = blockCache.getStats().getHitCachingRatio();
percent = (int) (ratio * 100);
this.metrics.blockCacheHitCachingRatio.set(percent);
// past N period block cache hit / hit caching ratios
cacheStats.rollMetricsPeriod();
ratio = cacheStats.getHitRatioPastNPeriods();
percent = (int) (ratio * 100);
this.metrics.blockCacheHitRatioPastNPeriods.set(percent);
ratio = cacheStats.getHitCachingRatioPastNPeriods();
percent = (int) (ratio * 100);
this.metrics.blockCacheHitCachingRatioPastNPeriods.set(percent);
}
float localityIndex = hdfsBlocksDistribution.getBlockLocalityIndex(
getServerName().getHostname());
int percent = (int) (localityIndex * 100);
this.metrics.hdfsBlocksLocalityIndex.set(percent);
}