Skip to content

Commit

Permalink
Issue ReactiveX#71: Added a Prometheus metrics adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
goldobin authored and RobWin committed Jul 27, 2017
1 parent 143f884 commit b5abf79
Show file tree
Hide file tree
Showing 9 changed files with 744 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void setUp() {
protectedSupplier = CircuitBreaker.decorateSupplier(circuitBreaker, stringSupplier);

CircuitBreaker circuitBreakerWithSubscriber = CircuitBreaker.ofDefaults("testCircuitBreakerWithSb");
circuitBreakerWithSubscriber.getEventStream().subscribe();
protectedSupplierWithSb = CircuitBreaker.decorateSupplier(circuitBreakerWithSubscriber, stringSupplier);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
=== Prometheus Metrics exporter
=== Prometheus Metrics Integration

==== Introduction

Integration of circuit breaker and rate limiter metrics with
https://github.com/prometheus/client_java[Prometheus simple client]
Integration with https://github.com/prometheus/client_java[Prometheus simple client]

Module provides exporters for `CircuitBreaker` and `RateLimiter` metrics.

For the circuit breaker library exports 2 metrics:

Expand All @@ -28,6 +29,15 @@ For the rate limiter following metric with default name `rate_limiter` and label

The names of the rate limiters and circuit breakers are exposed using label `name`.

This module also provides `CallMeter` -- a composite metric to measure single call/request metrics such as:
- execution time distribution,
- number of attempts and
- number of failures.

It is implemented in Prometheus simple client's style, supports labels and produces histogram and counter metrics.

Usage examples provided bellow in this section.

==== Dashboard Example

image::images/prometheus-dashboard.png[Circuit Breaker Dashboard Example]
Expand Down Expand Up @@ -64,4 +74,41 @@ final RateLimiter boo = rateLimiterRegistry.rateLimiter("boo");
collectorRegistry.register(RateLimiterExports.ofRateLimiterRegistry(rateLimiterRegistry));
--

For both it is possible to use just a collection of breakers and limiters instead of registry.
For both it is possible to use just a collection of breakers and limiters instead of registry.

===== Call Meter

Simple example without labels

[source,java]
--
final CollectorRegistry registry = new CollectorRegistry();

final CallMeter meter = CallMeter.of("foo_call", "Foo call help", registry);

CallMeter.decorateCompletionStageSupplier(meter, () -> supplyAsync(() -> { /* ... */ }));
--

Advanced example with labels

[source,java]
--
final CollectorRegistry registry = new CollectorRegistry();

final CallMeter meter = CallMeter
.builder()
.name("foo_call")
.help("Foo call help")
.labelNames("label_1")
.build()
.register(registry);

meter.labels("boo").executeRunnable(() -> { /* ... */ });

CallMeter.decorateCompletionStageSupplier(
meter.labels("baz"),
() -> supplyAsync(() -> { /* ... */ })
);

--

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface Timer {
*
* @param name the name of the timer
* @param metricRegistry the MetricRegistry
* @return a Bulkhead instance
* @return a Timer instance
*/
static Timer ofMetricRegistry(String name, MetricRegistry metricRegistry) {
return new TimerImpl(name, metricRegistry);
Expand All @@ -57,7 +57,7 @@ static Timer ofMetricRegistry(String name, MetricRegistry metricRegistry) {
* Creates a timer of a default MetricRegistry
*
* @param name the name of the timer
* @return a Bulkhead instance
* @return a Timer instance
*/
static Timer of(String name) {
return new TimerImpl(name, new MetricRegistry());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.resilience4j.prometheus;

import io.prometheus.client.Counter;
import io.prometheus.client.Histogram;

final class CallCollectors {
public final Histogram histogram;
public final Counter totalCounter;
public final Counter errorCounter;

CallCollectors(Histogram histogram, Counter totalCounter, Counter errorCounter) {
this.histogram = histogram;
this.totalCounter = totalCounter;
this.errorCounter = errorCounter;
}
}
Loading

0 comments on commit b5abf79

Please sign in to comment.