Search in sources :

Example 11 with Description

use of com.google.gerrit.metrics.Description in project gerrit by GerritCodeReview.

the class ProcMetricModule method procJvmGc.

private void procJvmGc(MetricMaker metrics) {
    CallbackMetric1<String, Long> gcCount = metrics.newCallbackMetric("proc/jvm/gc/count", Long.class, new Description("Number of GCs").setCumulative(), Field.ofString("gc_name", "The name of the garbage collector"));
    CallbackMetric1<String, Long> gcTime = metrics.newCallbackMetric("proc/jvm/gc/time", Long.class, new Description("Approximate accumulated GC elapsed time").setCumulative().setUnit(Units.MILLISECONDS), Field.ofString("gc_name", "The name of the garbage collector"));
    metrics.newTrigger(gcCount, gcTime, () -> {
        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            long count = gc.getCollectionCount();
            if (count != -1) {
                gcCount.set(gc.getName(), count);
            }
            long time = gc.getCollectionTime();
            if (time != -1) {
                gcTime.set(gc.getName(), time);
            }
        }
    });
}
Also used : Description(com.google.gerrit.metrics.Description) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

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