use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.
the class CallMeterTest method testInstrumentsFailedCall.
@Test
public void testInstrumentsFailedCall() throws Exception {
// Given
final CollectorRegistry registry = new CollectorRegistry();
final CallMeter timer = CallMeter.ofCollectorRegistry("some_call", "Some help", registry);
try {
// When
timer.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[] {}, new String[] {})).isEqualTo(1.0);
assertThat(registry.getSampleValue("some_call_failures_total", new String[] {}, new String[] {})).isEqualTo(1.0);
assertThat(registry.getSampleValue("some_call_latency_count", new String[] {}, new String[] {})).isEqualTo(0.0);
}
use of io.prometheus.client.CollectorRegistry in project resilience4j by resilience4j.
the class CircuitBreakerExportsTest method testExportsCircuitBreakerStates.
@Test
public void testExportsCircuitBreakerStates() {
// 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("closed", "open", "half_open").map(state -> Tuple.of(state, registry.getSampleValue("boo_circuit_breaker_states", new String[] { "name", "state" }, new String[] { "foo", state }))).toMap(t -> t);
// When
final Map<String, Double> closedStateValues = values.get();
circuitBreaker.transitionToOpenState();
final Map<String, Double> openStateValues = values.get();
circuitBreaker.transitionToHalfOpenState();
final Map<String, Double> halfOpenStateValues = values.get();
circuitBreaker.transitionToClosedState();
final Map<String, Double> closedStateValues2 = values.get();
// Then
assertThat(closedStateValues).isEqualTo(HashMap.of("closed", 1.0, "open", 0.0, "half_open", 0.0));
assertThat(openStateValues).isEqualTo(HashMap.of("closed", 0.0, "open", 1.0, "half_open", 0.0));
assertThat(halfOpenStateValues).isEqualTo(HashMap.of("closed", 0.0, "open", 0.0, "half_open", 1.0));
assertThat(closedStateValues2).isEqualTo(HashMap.of("closed", 1.0, "open", 0.0, "half_open", 0.0));
}
use of io.prometheus.client.CollectorRegistry in project modules-extra by CubeEngine.
the class Stats method onPreInit.
@Listener
public void onPreInit(GamePreInitializationEvent event) {
final CollectorRegistry registry = monitoring.getRegistry();
final InetSocketAddress bindAddr = new InetSocketAddress(config.bindAddress, config.bindPort);
registerDefaults(registry);
players.register(registry);
tps.register(registry);
loadedChunks.register(registry);
playersOnline.register(registry);
entities.register(registry);
tileEntities.register(registry);
try {
this.exporter = new HTTPServer(bindAddr, registry, true);
this.scheduler.scheduleAtFixedRate(this::sampleServer, config.samplingInterval.toMillis(), config.samplingInterval.toMillis(), TimeUnit.MILLISECONDS);
} catch (IOException e) {
e.printStackTrace();
}
}
use of io.prometheus.client.CollectorRegistry in project dcos-commons by mesosphere.
the class Metrics method configureMetricsEndpoints.
/**
* Appends endpoint servlets to the provided {@code context} which will serve codahale-style and prometheus-style
* metrics.
*/
public static void configureMetricsEndpoints(ServletContextHandler context, String codahaleMetricsEndpoint, String prometheusEndpoint) {
// Metrics
ServletHolder codahaleMetricsServlet = new ServletHolder("default", new com.codahale.metrics.servlets.MetricsServlet(metrics));
context.addServlet(codahaleMetricsServlet, codahaleMetricsEndpoint);
// Prometheus
CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(metrics));
ServletHolder prometheusServlet = new ServletHolder("prometheus", new io.prometheus.client.exporter.MetricsServlet(collectorRegistry));
context.addServlet(prometheusServlet, prometheusEndpoint);
}
use of io.prometheus.client.CollectorRegistry in project oxAuth by GluuFederation.
the class StatWS method createOpenMetricsResponse.
public static String createOpenMetricsResponse(StatResponse statResponse) throws IOException {
Writer writer = new StringWriter();
CollectorRegistry registry = new CollectorRegistry();
final Counter usersCounter = Counter.build().name("monthly_active_users").labelNames("month").help("Monthly active users").register(registry);
final Counter accessTokenCounter = Counter.build().name(StatService.ACCESS_TOKEN_KEY).labelNames("month", "grantType").help("Access Token").register(registry);
final Counter idTokenCounter = Counter.build().name(StatService.ID_TOKEN_KEY).labelNames("month", "grantType").help("Id Token").register(registry);
final Counter refreshTokenCounter = Counter.build().name(StatService.REFRESH_TOKEN_KEY).labelNames("month", "grantType").help("Refresh Token").register(registry);
final Counter umaTokenCounter = Counter.build().name(StatService.UMA_TOKEN_KEY).labelNames("month", "grantType").help("UMA Token").register(registry);
for (Map.Entry<String, StatResponseItem> entry : statResponse.getResponse().entrySet()) {
final String month = entry.getKey();
final StatResponseItem item = entry.getValue();
usersCounter.labels(month).inc(item.getMonthlyActiveUsers());
for (Map.Entry<String, Map<String, Long>> tokenEntry : item.getTokenCountPerGrantType().entrySet()) {
final String grantType = tokenEntry.getKey();
final Map<String, Long> tokenMap = tokenEntry.getValue();
accessTokenCounter.labels(month, grantType).inc(getToken(tokenMap, StatService.ACCESS_TOKEN_KEY));
idTokenCounter.labels(month, grantType).inc(getToken(tokenMap, StatService.ID_TOKEN_KEY));
refreshTokenCounter.labels(month, grantType).inc(getToken(tokenMap, StatService.REFRESH_TOKEN_KEY));
umaTokenCounter.labels(month, grantType).inc(getToken(tokenMap, StatService.UMA_TOKEN_KEY));
}
}
TextFormat.write004(writer, registry.metricFamilySamples());
return writer.toString();
}
Aggregations