use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class ProcMetricModuleTest method invalidName1.
@Test
public void invalidName1() {
exception.expect(IllegalArgumentException.class);
metrics.newCounter("invalid name", new Description("fail"));
}
use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class DataSourceProvider method exportPoolMetrics.
private void exportPoolMetrics(BasicDataSource pool) {
CallbackMetric1<Boolean, Integer> cnt = metrics.newCallbackMetric("sql/connection_pool/connections", Integer.class, new Description("SQL database connections").setGauge().setUnit("connections"), Field.ofBoolean("active"));
metrics.newTrigger(cnt, () -> {
synchronized (pool) {
cnt.set(true, pool.getNumActive());
cnt.set(false, pool.getNumIdle());
}
});
}
use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class ProcMetricModuleTest method callbackMetric0.
@Test
public void callbackMetric0() {
CallbackMetric0<Long> cntr = metrics.newCallbackMetric("test/count", Long.class, new Description("simple test").setCumulative());
AtomicInteger invocations = new AtomicInteger(0);
metrics.newTrigger(cntr, () -> {
invocations.getAndIncrement();
cntr.set(42L);
});
// Triggers run immediately with DropWizard binding.
assertThat(invocations.get()).isEqualTo(1);
Gauge<Long> raw = gauge("test/count");
assertThat(raw.getValue()).isEqualTo(42);
// Triggers are debounced to avoid being fired too frequently.
assertThat(invocations.get()).isEqualTo(1);
}
use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class JGitMetricModule method configure.
@Override
protected void configure(MetricMaker metrics) {
metrics.newCallbackMetric("jgit/block_cache/cache_used", Long.class, new Description("Bytes of memory retained in JGit block cache.").setGauge().setUnit(Units.BYTES), new Supplier<Long>() {
@Override
public Long get() {
return WindowCacheStatAccessor.getOpenBytes();
}
});
metrics.newCallbackMetric("jgit/block_cache/open_files", Integer.class, new Description("File handles held open by JGit block cache.").setGauge().setUnit("fds"), new Supplier<Integer>() {
@Override
public Integer get() {
return WindowCacheStatAccessor.getOpenFiles();
}
});
}
use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.
the class ProcMetricModule method procJvmMemory.
private void procJvmMemory(MetricMaker metrics) {
CallbackMetric0<Long> heapCommitted = metrics.newCallbackMetric("proc/jvm/memory/heap_committed", Long.class, new Description("Amount of memory guaranteed for user objects.").setGauge().setUnit(Units.BYTES));
CallbackMetric0<Long> heapUsed = metrics.newCallbackMetric("proc/jvm/memory/heap_used", Long.class, new Description("Amount of memory holding user objects.").setGauge().setUnit(Units.BYTES));
CallbackMetric0<Long> nonHeapCommitted = metrics.newCallbackMetric("proc/jvm/memory/non_heap_committed", Long.class, new Description("Amount of memory guaranteed for classes, etc.").setGauge().setUnit(Units.BYTES));
CallbackMetric0<Long> nonHeapUsed = metrics.newCallbackMetric("proc/jvm/memory/non_heap_used", Long.class, new Description("Amount of memory holding classes, etc.").setGauge().setUnit(Units.BYTES));
CallbackMetric0<Integer> objectPendingFinalizationCount = metrics.newCallbackMetric("proc/jvm/memory/object_pending_finalization_count", Integer.class, new Description("Approximate number of objects needing finalization.").setGauge().setUnit("objects"));
MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
metrics.newTrigger(ImmutableSet.<CallbackMetric<?>>of(heapCommitted, heapUsed, nonHeapCommitted, nonHeapUsed, objectPendingFinalizationCount), () -> {
try {
MemoryUsage stats = memory.getHeapMemoryUsage();
heapCommitted.set(stats.getCommitted());
heapUsed.set(stats.getUsed());
} catch (IllegalArgumentException e) {
// MXBean may throw due to a bug in Java 7; ignore.
}
MemoryUsage stats = memory.getNonHeapMemoryUsage();
nonHeapCommitted.set(stats.getCommitted());
nonHeapUsed.set(stats.getUsed());
objectPendingFinalizationCount.set(memory.getObjectPendingFinalizationCount());
});
}
Aggregations