Search in sources :

Example 6 with Description

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"));
}
Also used : Description(com.google.gerrit.metrics.Description) Test(org.junit.Test)

Example 7 with Description

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());
        }
    });
}
Also used : Description(com.google.gerrit.metrics.Description)

Example 8 with Description

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);
}
Also used : Description(com.google.gerrit.metrics.Description) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 9 with Description

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();
        }
    });
}
Also used : Description(com.google.gerrit.metrics.Description)

Example 10 with Description

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());
    });
}
Also used : Description(com.google.gerrit.metrics.Description) MemoryMXBean(java.lang.management.MemoryMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

Description (com.google.gerrit.metrics.Description)11 Test (org.junit.Test)6 Counter (com.codahale.metrics.Counter)3 Counter0 (com.google.gerrit.metrics.Counter0)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1