Search in sources :

Example 6 with CollectorRegistry

use of io.prometheus.client.CollectorRegistry in project promregator by promregator.

the class PromregatorApplication method collectorRegistry.

@Bean
public CollectorRegistry collectorRegistry() {
    CollectorRegistry cr = CollectorRegistry.defaultRegistry;
    DefaultExports.initialize();
    return cr;
}
Also used : CollectorRegistry(io.prometheus.client.CollectorRegistry) Bean(org.springframework.context.annotation.Bean)

Example 7 with CollectorRegistry

use of io.prometheus.client.CollectorRegistry in project curiostack by curioswitch.

the class MonitoringModule method collectorRegistry.

@Provides
@Singleton
static CollectorRegistry collectorRegistry() {
    CollectorRegistry registry = CollectorRegistry.defaultRegistry;
    DefaultExports.initialize();
    configureLogMetrics();
    return registry;
}
Also used : CollectorRegistry(io.prometheus.client.CollectorRegistry) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 8 with CollectorRegistry

use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.

the class CallMeterTest method testInstrumentsFailedCallWithLabels.

@Test
public void testInstrumentsFailedCallWithLabels() throws Exception {
    // Given
    final CollectorRegistry registry = new CollectorRegistry();
    final CallMeter timer = CallMeter.builder().name("some_call").help("Some test help").labelNames("label_1").build().register(registry);
    try {
        // When
        timer.labels("foo").executeRunnable(() -> {
            try {
                Thread.sleep(50);
                throw new SomeAppException("Test Exception");
            } catch (InterruptedException e) {
                fail();
            }
        });
    } catch (SomeAppException e) {
        assertThat(e.getMessage()).isEqualTo("Test Exception");
    // ignore
    }
    // Then
    assertThat(registry.getSampleValue("some_call_total", new String[] { "label_1" }, new String[] { "foo" })).isEqualTo(1.0);
    assertThat(registry.getSampleValue("some_call_failures_total", new String[] { "label_1" }, new String[] { "foo" })).isEqualTo(1.0);
    assertThat(registry.getSampleValue("some_call_latency_count", new String[] { "label_1" }, new String[] { "foo" })).isEqualTo(0.0);
}
Also used : CollectorRegistry(io.prometheus.client.CollectorRegistry) Test(org.junit.Test)

Example 9 with CollectorRegistry

use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.

the class CallMeterTest method testInstrumentsSuccessfulCall.

@Test
public void testInstrumentsSuccessfulCall() throws Exception {
    // Given
    final CollectorRegistry registry = new CollectorRegistry();
    final CallMeter timer = CallMeter.ofCollectorRegistry("some_call", "Some help", registry);
    // When
    timer.executeRunnable(() -> {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            fail();
        }
    });
    // Then
    assertThat(registry.getSampleValue("some_call_total", new String[] {}, new String[] {})).isEqualTo(1.0);
    assertThat(registry.getSampleValue("some_call_failures_total", new String[] {}, new String[] {})).isEqualTo(0.0);
    assertThat(registry.getSampleValue("some_call_latency_count", new String[] {}, new String[] {})).isEqualTo(1.0);
}
Also used : CollectorRegistry(io.prometheus.client.CollectorRegistry) Test(org.junit.Test)

Example 10 with CollectorRegistry

use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.

the class CallMeterTest method testInstrumentsSuccessfulCallWithLabels.

@Test
public void testInstrumentsSuccessfulCallWithLabels() throws Exception {
    // Given
    final CollectorRegistry registry = new CollectorRegistry();
    final CallMeter timer = CallMeter.builder().name("some_call").help("Some call help").labelNames("label_1").build().register(registry);
    // When
    timer.labels("boo").executeRunnable(() -> {
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            fail();
        }
    });
    // Then
    assertThat(registry.getSampleValue("some_call_total", new String[] { "label_1" }, new String[] { "boo" })).isEqualTo(1.0);
    assertThat(registry.getSampleValue("some_call_failures_total", new String[] { "label_1" }, new String[] { "boo" })).isEqualTo(0.0);
    assertThat(registry.getSampleValue("some_call_latency_count", new String[] { "label_1" }, new String[] { "boo" })).isEqualTo(1.0);
}
Also used : CollectorRegistry(io.prometheus.client.CollectorRegistry) Test(org.junit.Test)

Aggregations

CollectorRegistry (io.prometheus.client.CollectorRegistry)13 Test (org.junit.Test)7 Tuple (io.vavr.Tuple)3 HashMap (io.vavr.collection.HashMap)3 HashSet (io.vavr.collection.HashSet)3 Map (io.vavr.collection.Map)3 Collections.singleton (java.util.Collections.singleton)3 Collections.singletonList (java.util.Collections.singletonList)3 Supplier (java.util.function.Supplier)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)2 CircuitBreakerOpenException (io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException)2 CircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry)2 InMemoryCircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry)2 HTTPServer (io.prometheus.client.exporter.HTTPServer)2 InetSocketAddress (java.net.InetSocketAddress)2 Provides (dagger.Provides)1 RateLimiter (io.github.resilience4j.ratelimiter.RateLimiter)1 RateLimiterConfig (io.github.resilience4j.ratelimiter.RateLimiterConfig)1 RateLimiterRegistry (io.github.resilience4j.ratelimiter.RateLimiterRegistry)1