diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java index cc97c21153d72..8866c8498664d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.component.CloseableComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.cache.bloom.BloomCache; @@ -52,8 +53,13 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo private final BloomCache bloomCache; + private final TimeValue refreshInterval; + private ClusterService clusterService; + private long latestCacheStatsTimestamp = -1; + private CacheStats latestCacheStats; + @Inject public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache, FieldDataCache fieldDataCache, QueryParserCache queryParserCache, IdCache idCache, BloomCache bloomCache) { super(index, indexSettings); @@ -62,6 +68,10 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo this.queryParserCache = queryParserCache; this.idCache = idCache; this.bloomCache = bloomCache; + + this.refreshInterval = componentSettings.getAsTime("stats.refresh_interval", TimeValue.timeValueSeconds(1)); + + logger.debug("Using stats.refresh_interval [{}]", refreshInterval); } @Inject(optional = true) @@ -72,9 +82,14 @@ public void setClusterService(@Nullable ClusterService clusterService) { } } - public CacheStats stats() { - FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats(); - return new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, bloomCache.sizeInBytes()); + public synchronized CacheStats stats() { + long timestamp = System.currentTimeMillis(); + if ((timestamp - latestCacheStatsTimestamp) > refreshInterval.millis()) { + FilterCache.EntriesStats filterEntriesStats = filterCache.entriesStats(); + latestCacheStats = new CacheStats(fieldDataCache.evictions(), filterCache.evictions(), fieldDataCache.sizeInBytes(), filterEntriesStats.sizeInBytes, filterEntriesStats.count, bloomCache.sizeInBytes()); + latestCacheStatsTimestamp = timestamp; + } + return latestCacheStats; } public FilterCache filter() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java index 81a7e5f448bd2..944ef8e572f9f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/jvm/JvmService.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; /** * @author kimchy (shay.banon) @@ -30,16 +31,28 @@ public class JvmService extends AbstractComponent { private final JvmInfo jvmInfo; + private final TimeValue refreshInterval; + + private JvmStats jvmStats; + @Inject public JvmService(Settings settings) { super(settings); this.jvmInfo = JvmInfo.jvmInfo(); + this.jvmStats = JvmStats.jvmStats(); + + this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1)); + + logger.debug("Using refresh_interval [{}]", refreshInterval); } public JvmInfo info() { return this.jvmInfo; } - public JvmStats stats() { - return JvmStats.jvmStats(); + public synchronized JvmStats stats() { + if ((System.currentTimeMillis() - jvmStats.timestamp()) > refreshInterval.millis()) { + jvmStats = JvmStats.jvmStats(); + } + return jvmStats; } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java index 20cbf1414d5da..03390192d345b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java @@ -41,7 +41,7 @@ public class OsService extends AbstractComponent { super(settings); this.probe = probe; - this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); + this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1)); this.info = probe.osInfo(); this.info.refreshInterval = refreshInterval.millis(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java index d85e5d73fa7b2..d10a9631d93f4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/monitor/process/ProcessService.java @@ -41,7 +41,7 @@ public class ProcessService extends AbstractComponent { super(settings); this.probe = probe; - this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(5)); + this.refreshInterval = componentSettings.getAsTime("refresh_interval", TimeValue.timeValueSeconds(1)); this.info = probe.processInfo(); this.info.refreshInterval = refreshInterval.millis();