Skip to content

Commit

Permalink
Script: Time series compile and cache evict metrics
Browse files Browse the repository at this point in the history
Collects compilation and cache eviction metrics for
each script context.

Metrics are available in _nodes/stats in 5m/15m/1d
buckets.

Refs: elastic#62899
  • Loading branch information
stu-elastic committed Oct 13, 2021
1 parent 0f9848e commit a6c7a93
Show file tree
Hide file tree
Showing 3 changed files with 682 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/src/main/java/org/elasticsearch/script/ScriptMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,38 @@ public class ScriptMetrics {
final CounterMetric compilationsMetric = new CounterMetric();
final CounterMetric cacheEvictionsMetric = new CounterMetric();
final CounterMetric compilationLimitTriggered = new CounterMetric();
final TimeSeriesCounter compilationsHistory = timeSeriesCounter();
final TimeSeriesCounter cacheEvictionsHistory = timeSeriesCounter();
final int[] TIME_PERIODS = { 5 * TimeSeriesCounter.MINUTE, 15 * TimeSeriesCounter.MINUTE, 24 * TimeSeriesCounter.HOUR };

public static TimeSeriesCounter timeSeriesCounter() {
return TimeSeriesCounter.nestedCounter(24 * 4, 15 * TimeSeriesCounter.MINUTE, 60, 15);
}

public void onCompilation() {
compilationsMetric.inc();
compilationsHistory.inc();
}

public void onCacheEviction() {
cacheEvictionsMetric.inc();
cacheEvictionsHistory.inc();
}

public void onCompilationLimit() {
compilationLimitTriggered.inc();
}

public ScriptContextStats stats(String context) {
long timestamp = compilationsHistory.timestamp();
int[] compilations = compilationsHistory.counts(timestamp, TIME_PERIODS);
int[] cacheEvictions = cacheEvictionsHistory.counts(timestamp, TIME_PERIODS);
return new ScriptContextStats(
context,
compilationsMetric.count(),
cacheEvictionsMetric.count(),
compilationLimitTriggered.count(),
new ScriptContextStats.TimeSeries(),
new ScriptContextStats.TimeSeries()
new ScriptContextStats.TimeSeries(compilations[0], compilations[1], compilations[2]),
new ScriptContextStats.TimeSeries(cacheEvictions[0], cacheEvictions[1], cacheEvictions[2])
);
}}
Loading

0 comments on commit a6c7a93

Please sign in to comment.