Add additional JGit WindowCache metrics
Adapt JGit metrics to new WindowCache metrics introduced in JGit 5.1.13: - cache_used: replace use of deprecated method - open_files: adapt type which changed from int to long Add the following new metrics: - avg_load_time - eviction_count - eviction_ratio - hit_count - hit_ratio - load_failure_count - load_failure_ratio - load_success_count - miss_count - miss_ratio - cache_used_per_repository, limited to the top 1000 repositories having most data cached Change-Id: I6d4c76a85943ea23d57d15d4f6bdeb91711a1a63
This commit is contained in:
@@ -132,6 +132,18 @@ topic submissions that concluded successfully.
|
||||
|
||||
* `jgit/block_cache/cache_used`: Bytes of memory retained in JGit block cache.
|
||||
* `jgit/block_cache/open_files`: File handles held open by JGit block cache.
|
||||
* `avg_load_time` Average time to load a cache entry for JGit block cache.
|
||||
* `eviction_count` : Cache evictions for JGit block cache.
|
||||
* `eviction_ratio` : Cache eviction ratio for JGit block cache.
|
||||
* `hit_count` : Cache hits for JGit block cache.
|
||||
* `hit_ratio` : Cache hit ratio for JGit block cache.
|
||||
* `load_failure_count` : Failed cache loads for JGit block cache.
|
||||
* `load_failure_ratio` : Failed cache load ratio for JGit block cache.
|
||||
* `load_success_count` : Successful cache loads for JGit block cache.
|
||||
* `miss_count` : Cache misses for JGit block cache.
|
||||
* `miss_ratio` : Cache miss ratio for JGit block cache.
|
||||
* `cache_used_per_repository` : Bytes of memory retained per repository for the top N repositories
|
||||
having most data in the cache. The number N of reported repositories is limited to 1000.
|
||||
|
||||
=== Git
|
||||
|
||||
|
||||
@@ -14,12 +14,18 @@
|
||||
|
||||
package com.google.gerrit.metrics.proc;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.gerrit.metrics.CallbackMetric1;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
import com.google.gerrit.metrics.Description.Units;
|
||||
import com.google.gerrit.metrics.Field;
|
||||
import com.google.gerrit.metrics.MetricMaker;
|
||||
import java.util.Map;
|
||||
import org.eclipse.jgit.storage.file.WindowCacheStats;
|
||||
|
||||
public class JGitMetricModule extends MetricModule {
|
||||
private static final long MAX_REPO_COUNT = 1000;
|
||||
|
||||
@Override
|
||||
protected void configure(MetricMaker metrics) {
|
||||
metrics.newCallbackMetric(
|
||||
@@ -28,12 +34,153 @@ public class JGitMetricModule extends MetricModule {
|
||||
new Description("Bytes of memory retained in JGit block cache.")
|
||||
.setGauge()
|
||||
.setUnit(Units.BYTES),
|
||||
WindowCacheStats::getOpenBytes);
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getOpenByteCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/open_files",
|
||||
Integer.class,
|
||||
Long.class,
|
||||
new Description("File handles held open by JGit block cache.").setGauge().setUnit("fds"),
|
||||
WindowCacheStats::getOpenFiles);
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getOpenFileCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/avg_load_time",
|
||||
Double.class,
|
||||
new Description("Average time to load a cache entry for JGit block cache.")
|
||||
.setGauge()
|
||||
.setUnit(Units.NANOSECONDS),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getAverageLoadTime();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/eviction_count",
|
||||
Long.class,
|
||||
new Description("Cache evictions for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getEvictionCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/eviction_ratio",
|
||||
Double.class,
|
||||
new Description("Cache eviction ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getEvictionRatio();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/hit_count",
|
||||
Long.class,
|
||||
new Description("Cache hits for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getHitCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/hit_ratio",
|
||||
Double.class,
|
||||
new Description("Cache hit ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getHitRatio();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_failure_count",
|
||||
Long.class,
|
||||
new Description("Failed cache loads for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getLoadFailureCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_failure_ratio",
|
||||
Double.class,
|
||||
new Description("Failed cache load ratio for JGit block cache.").setGauge(),
|
||||
new Supplier<Double>() {
|
||||
@Override
|
||||
public Double get() {
|
||||
return WindowCacheStats.getStats().getLoadFailureRatio();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/load_success_count",
|
||||
Long.class,
|
||||
new Description("Successfull cache loads for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getLoadSuccessCount();
|
||||
}
|
||||
});
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/miss_count",
|
||||
Long.class,
|
||||
new Description("Cache misses for JGit block cache.").setGauge(),
|
||||
new Supplier<Long>() {
|
||||
@Override
|
||||
public Long get() {
|
||||
return WindowCacheStats.getStats().getMissCount();
|
||||
}
|
||||
});
|
||||
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/miss_ratio",
|
||||
Double.class,
|
||||
new Description("Cache miss ratio for JGit block cache.").setGauge(),
|
||||
WindowCacheStats.getStats()::getMissRatio);
|
||||
|
||||
CallbackMetric1<String, Long> repoEnt =
|
||||
metrics.newCallbackMetric(
|
||||
"jgit/block_cache/cache_used_per_repository",
|
||||
Long.class,
|
||||
new Description(
|
||||
"Bytes of memory retained per repository for the top repositories "
|
||||
+ "having most data in the cache.")
|
||||
.setGauge()
|
||||
.setUnit("byte"),
|
||||
Field.ofString("repository_name"));
|
||||
metrics.newTrigger(
|
||||
repoEnt,
|
||||
() -> {
|
||||
Map<String, Long> cacheMap = WindowCacheStats.getStats().getOpenByteCountPerRepository();
|
||||
if (cacheMap.isEmpty()) {
|
||||
repoEnt.forceCreate("");
|
||||
} else {
|
||||
cacheMap.entrySet().stream()
|
||||
.sorted(Map.Entry.<String, Long>comparingByValue().reversed())
|
||||
.limit(MAX_REPO_COUNT)
|
||||
.forEach(e -> repoEnt.set(e.getKey(), e.getValue()));
|
||||
repoEnt.prune();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user