use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.
the class CircuitBreakerExportsTest method testExportsCircuitBreakerMetrics.
@Test
public void testExportsCircuitBreakerMetrics() {
// Given
final CollectorRegistry registry = new CollectorRegistry();
final CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("foo");
CircuitBreakerExports.ofIterable("boo_circuit_breaker", singletonList(circuitBreaker)).register(registry);
final Supplier<Map<String, Double>> values = () -> HashSet.of("successful", "failed", "not_permitted", "buffered", "buffered_max").map(callType -> Tuple.of(callType, registry.getSampleValue("boo_circuit_breaker_calls", new String[] { "name", "call_result" }, new String[] { "foo", callType }))).toMap(t -> t);
// When
final Map<String, Double> initialValues = values.get();
circuitBreaker.executeRunnable(() -> {
});
final Map<String, Double> afterSuccessValues = values.get();
try {
circuitBreaker.executeRunnable(() -> {
throw new SomeAppException("Some exception");
});
} catch (RuntimeException e) {
// expected
}
final Map<String, Double> afterFailureValues = values.get();
circuitBreaker.transitionToOpenState();
try {
circuitBreaker.executeRunnable(() -> {
});
} catch (CircuitBreakerOpenException e) {
// expected
}
final Map<String, Double> afterDeclinedValues = values.get();
// Then
assertThat(initialValues).isEqualTo(HashMap.of("successful", 0.0, "failed", 0.0, "not_permitted", 0.0, "buffered", 0.0, "buffered_max", 100.0));
assertThat(afterSuccessValues).isEqualTo(HashMap.of("successful", 1.0, "failed", 0.0, "not_permitted", 0.0, "buffered", 1.0, "buffered_max", 100.0));
assertThat(afterFailureValues).isEqualTo(HashMap.of("successful", 1.0, "failed", 1.0, "not_permitted", 0.0, "buffered", 2.0, "buffered_max", 100.0));
assertThat(afterDeclinedValues).isEqualTo(HashMap.of("successful", 1.0, "failed", 1.0, "not_permitted", 1.0, "buffered", 2.0, "buffered_max", 100.0));
}
use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.
the class RateLimiterExportsTest method testExportsRateLimiterMetrics.
@Test
public void testExportsRateLimiterMetrics() {
// Given
final CollectorRegistry registry = new CollectorRegistry();
final RateLimiter rateLimiter = RateLimiter.ofDefaults("foo");
RateLimiterExports.ofIterable("boo_rate_limiter", singletonList(rateLimiter)).register(registry);
final Supplier<Map<String, Double>> values = () -> HashSet.of("available_permissions", "waiting_threads").map(param -> Tuple.of(param, registry.getSampleValue("boo_rate_limiter", new String[] { "name", "param" }, new String[] { "foo", param }))).toMap(t -> t);
// When
final Map<String, Double> initialValues = values.get();
// Then
assertThat(initialValues).isEqualTo(HashMap.of("available_permissions", 50.0, "waiting_threads", 0.0));
}
use of io.prometheus.client.CollectorRegistry in project infrautils by opendaylight.
the class MetricsPrometheusExampleMain method main.
public static void main(String[] args) throws IOException {
// see also OsgiWebInitializer
CollectorRegistry collectorRegistry = new CollectorRegistrySingleton();
PrometheusMetricProviderImpl metricProvider = new PrometheusMetricProviderImpl(collectorRegistry);
MetricsExample metricsExample = new MetricsExample(metricProvider);
metricsExample.init();
HTTPServer server = new HTTPServer(new InetSocketAddress("localhost", 1234), collectorRegistry);
System.in.read();
server.stop();
metricsExample.close();
metricProvider.close();
}
Aggregations