Search in sources :

Example 1 with Description

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

the class ProcMetricModuleTest method invalidName2.

@Test
public void invalidName2() {
    exception.expect(IllegalArgumentException.class);
    metrics.newCounter("invalid/ name", new Description("fail"));
}
Also used : Description(com.google.gerrit.metrics.Description) Test(org.junit.Test)

Example 2 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 3 with Description

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

the class ProcMetricModule method procJvmThread.

private void procJvmThread(MetricMaker metrics) {
    ThreadMXBean thread = ManagementFactory.getThreadMXBean();
    metrics.newCallbackMetric("proc/jvm/thread/num_live", Integer.class, new Description("Current live thread count").setGauge().setUnit("threads"), thread::getThreadCount);
    metrics.newCallbackMetric("proc/jvm/thread/num_daemon_live", Integer.class, new Description("Current live daemon threads count").setGauge().setUnit("threads"), thread::getDaemonThreadCount);
    metrics.newCallbackMetric("proc/jvm/thread/num_peak_live", Integer.class, new Description("Peak live thread count since the Java virtual machine started or peak was reset").setGauge().setUnit("threads"), thread::getPeakThreadCount);
    metrics.newCallbackMetric("proc/jvm/thread/num_total_started", Long.class, new Description("Total number of threads created and also started since the Java virtual machine started").setGauge().setUnit("threads"), thread::getTotalStartedThreadCount);
    if (thread.isSynchronizerUsageSupported()) {
        metrics.newCallbackMetric("proc/jvm/thread/num_deadlocked_threads", Integer.class, new Description("number of threads that are deadlocked waiting for object monitors or ownable synchronizers").setGauge().setUnit("threads"), () -> {
            long[] deadlocked = thread.findDeadlockedThreads();
            if (deadlocked == null) {
                return 0;
            }
            return deadlocked.length;
        });
    } else {
        metrics.newCallbackMetric("proc/jvm/thread/num_deadlocked_threads", Integer.class, new Description("number of threads that are deadlocked waiting to acquire object monitors").setGauge().setUnit("threads"), () -> {
            long[] deadlocked = thread.findMonitorDeadlockedThreads();
            if (deadlocked == null) {
                return 0;
            }
            return deadlocked.length;
        });
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) Description(com.google.gerrit.metrics.Description)

Example 4 with Description

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

the class PerformanceLogContextTest method timerMetricsInsidePerformanceLogContextCreatePerformanceLogNullValuesAllowed.

@Test
public void timerMetricsInsidePerformanceLogContextCreatePerformanceLogNullValuesAllowed() {
    assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
    assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
    try (PerformanceLogContext traceContext = new PerformanceLogContext(config, performanceLoggers)) {
        assertThat(LoggingContext.getInstance().isPerformanceLogging()).isTrue();
        Timer1<String> timer1 = metricMaker.newTimer("test1/latency", new Description("Latency metric for testing"), Field.ofString("project", Metadata.Builder::projectName).build());
        timer1.start(null).close();
        Timer2<String, String> timer2 = metricMaker.newTimer("test2/latency", new Description("Latency metric for testing"), Field.ofString("project", Metadata.Builder::projectName).build(), Field.ofString("branch", Metadata.Builder::branchName).build());
        timer2.start(null, null).close();
        Timer3<String, String, String> timer3 = metricMaker.newTimer("test3/latency", new Description("Latency metric for testing"), Field.ofString("project", Metadata.Builder::projectName).build(), Field.ofString("branch", Metadata.Builder::branchName).build(), Field.ofString("revision", Metadata.Builder::revision).build());
        timer3.start(null, null, null).close();
        assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).hasSize(3);
    }
    assertThat(testPerformanceLogger.logEntries()).containsExactly(PerformanceLogEntry.create("test1/latency", Metadata.empty()), PerformanceLogEntry.create("test2/latency", Metadata.empty()), PerformanceLogEntry.create("test3/latency", Metadata.empty())).inOrder();
    assertThat(LoggingContext.getInstance().isPerformanceLogging()).isFalse();
    assertThat(LoggingContext.getInstance().getPerformanceLogRecords()).isEmpty();
}
Also used : Description(com.google.gerrit.metrics.Description) Test(org.junit.Test)

Example 5 with Description

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

the class ProcMetricModuleTest method counterPrefixFields.

@Test
public void counterPrefixFields() {
    Counter1<String> cntr = metrics.newCounter("test/count", new Description("simple test").setCumulative().setFieldOrdering(FieldOrdering.PREFIX_FIELDS_BASENAME), Field.ofString("action", Field.ignoreMetadata()).build());
    Counter total = get("test/count_total", Counter.class);
    assertThat(total.getCount()).isEqualTo(0);
    cntr.increment("passed");
    Counter passed = get("test/passed/count", Counter.class);
    assertThat(total.getCount()).isEqualTo(1);
    assertThat(passed.getCount()).isEqualTo(1);
    cntr.incrementBy("failed", 5);
    Counter failed = get("test/failed/count", Counter.class);
    assertThat(total.getCount()).isEqualTo(6);
    assertThat(passed.getCount()).isEqualTo(1);
    assertThat(failed.getCount()).isEqualTo(5);
}
Also used : Description(com.google.gerrit.metrics.Description) Counter(com.codahale.metrics.Counter) Test(org.junit.Test)

Aggregations

Description (com.google.gerrit.metrics.Description)17 Test (org.junit.Test)10 Counter (com.codahale.metrics.Counter)3 Timer0 (com.google.gerrit.metrics.Timer0)3 MemoryUsage (java.lang.management.MemoryUsage)2 Counter0 (com.google.gerrit.metrics.Counter0)1 Metadata (com.google.gerrit.server.logging.Metadata)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1