Search in sources :

Example 26 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.

the class TimerTest method recordThrowable.

@DisplayName("record throwables")
@Test
default void recordThrowable() {
    MeterRegistry registry = new SimpleMeterRegistry();
    Supplier<String> timed = () -> registry.timer("timer").record(() -> "");
    timed.get();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 27 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.

the class MetricsTest method metricCanBeCreatedBeforeStaticRegistryIsConfigured.

@Test
void metricCanBeCreatedBeforeStaticRegistryIsConfigured() {
    // doesn't blow up
    Counter counter = Metrics.counter("counter");
    counter.increment();
    SimpleMeterRegistry simple = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
    Metrics.addRegistry(simple);
    counter.increment();
    assertThat(Metrics.globalRegistry.get("counter").counter().count()).isEqualTo(1.0);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 28 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.

the class MicrometerMetricsPublisherCommandTest method testCumulativeCounters.

@Disabled("CI is failing often asserting that the count is 23")
@Test
void testCumulativeCounters() throws Exception {
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("MicrometerCOMMAND-A");
    HystrixCommandProperties properties = new HystrixPropertiesCommandDefault(key, propertiesSetter);
    HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key, groupKey, properties);
    HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key, groupKey, properties, metrics);
    SimpleMeterRegistry registry = new SimpleMeterRegistry();
    MicrometerMetricsPublisherCommand metricsPublisherCommand = new MicrometerMetricsPublisherCommand(registry, key, groupKey, metrics, circuitBreaker, properties);
    metricsPublisherCommand.initialize();
    for (int i = 0; i < 3; i++) {
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        Thread.sleep(10);
        new TimeoutCommand(key).execute();
        new SuccessCommand(key).execute();
        new FailureCommand(key).execute();
        new FailureCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        Thread.sleep(10);
        new SuccessCommand(key).execute();
    }
    Iterable<Tag> tags = Tags.of("group", "MicrometerGROUP", "key", "MicrometerCOMMAND-A");
    assertExecutionMetric(registry, "success", 24.0);
    assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "timeout").functionCounter().count()).isEqualTo(3.0);
    assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "failure").functionCounter().count()).isEqualTo(6.0);
    assertThat(registry.get("hystrix.execution").tags(tags).tags("event", "short_circuited").functionCounter().count()).isEqualTo(0.0);
    assertThat(registry.get("hystrix.circuit.breaker.open").tags(tags).gauge().value()).isEqualTo(0.0);
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Tag(io.micrometer.core.instrument.Tag) HystrixPropertiesCommandDefault(com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 29 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.

the class ProcessorMetricsTest method openJ9CpuMetrics.

@Test
void openJ9CpuMetrics() {
    assumeTrue(classExists("com.ibm.lang.management.OperatingSystemMXBean"));
    MeterRegistry registry = new SimpleMeterRegistry();
    new ProcessorMetrics().bindTo(registry);
    /*
         * We can't assert on values because these methods are documented to return "-1"
         * on the first call and a positive value - if supported - on subsequent calls.
         * This holds true for "system.cpu.usage" but not for "process.cpu.usage". The latter
         * needs some milliseconds of sleep before it actually returns a positive value
         * on a supported system. Thread.sleep() is flaky, though.
         */
    registry.get("system.cpu.usage").gauge();
    registry.get("process.cpu.usage").gauge();
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 30 with SimpleMeterRegistry

use of io.micrometer.core.instrument.simple.SimpleMeterRegistry in project micrometer by micrometer-metrics.

the class DistributionSummaryTest method histogramsInCumulativeMode.

@Test
void histogramsInCumulativeMode() {
    MockClock clock = new MockClock();
    MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
    DistributionSummary summary = DistributionSummary.builder("my.summary").sla(1).register(registry);
    summary.record(1);
    // Histogram bucket counts DO roll over at the step interval, so decay.
    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1, 1));
    clock.add(SimpleConfig.DEFAULT.step());
    assertThat(summary.takeSnapshot().histogramCounts()).containsExactly(new CountAtBucket(1, 0));
}
Also used : SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CountAtBucket(io.micrometer.core.instrument.distribution.CountAtBucket) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)42 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)20 Test (org.junit.jupiter.api.Test)20 Test (org.junit.Test)18 Match (io.vertx.micrometer.Match)8 Timer (io.micrometer.core.instrument.Timer)6 LongTaskTimer (io.micrometer.core.instrument.LongTaskTimer)5 MockClock (io.micrometer.core.instrument.MockClock)5 Counter (io.micrometer.core.instrument.Counter)4 DistributionSummary (io.micrometer.core.instrument.DistributionSummary)4 Gauge (io.micrometer.core.instrument.Gauge)4 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)2 Issue (io.micrometer.core.Issue)2 Tag (io.micrometer.core.instrument.Tag)2 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)2 CountAtBucket (io.micrometer.core.instrument.distribution.CountAtBucket)2 SimpleConfig (io.micrometer.core.instrument.simple.SimpleConfig)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)2