use of io.micrometer.core.instrument.MeterRegistry in project drools by kiegroup.
the class MicrometerUtils method triggerMicrometer.
public void triggerMicrometer(BaseNode node, long evalCount, long elapsedTimeInNanos) {
MeterRegistry meterRegistry = Metrics.globalRegistry;
MicrometerUtils.triggerMicrometer(averageElapsedTimeCache, tags -> Timer.builder("org.drools.metric.elapsed.time.per.evaluation").tags(tags).register(meterRegistry), timer -> timer.record(Duration.ofNanos(elapsedTimeInNanos / evalCount)), node);
MicrometerUtils.triggerMicrometer(elapsedTimeCache, tags -> Timer.builder("org.drools.metric.elapsed.time").tags(tags).register(meterRegistry), timer -> timer.record(Duration.ofNanos(elapsedTimeInNanos)), node);
MicrometerUtils.triggerMicrometer(evaluationCountCache, tags -> Counter.builder("org.drools.metric.evaluation.count").tags(tags).register(meterRegistry), counter -> counter.increment(evalCount), node);
}
use of io.micrometer.core.instrument.MeterRegistry in project hono by eclipse.
the class MicrometerBasedMetricsTest method testConnectionTimeDuration.
/**
* Verifies that the connection time duration is recorded for the given tenant when devices get connected and
* disconnected.
*
* @param registry The registry that the tests should be run against.
*/
@ParameterizedTest
@MethodSource("registries")
public void testConnectionTimeDuration(final MeterRegistry registry) {
final MeterRegistry meterRegistry = Mockito.spy(registry);
final Metrics metrics = new MicrometerBasedMetrics(meterRegistry, mock(Vertx.class));
metrics.incrementConnections("TEST_TENANT");
metrics.decrementConnections("TEST_TENANT");
verify(meterRegistry, times(1)).timer(MicrometerBasedMetrics.METER_CONNECTIONS_AUTHENTICATED_DURATION, Tags.of(MetricsTags.getTenantTag("TEST_TENANT")));
}
use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.
the class StatsProviderTest method testStatsProviderStartAndClose.
@Test
public void testStatsProviderStartAndClose() {
// To improve test case isolation, create a new registry instead of using the global one.
@Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).with(MetricsConfig.ENABLE_INFLUXDB_REPORTER, false).build();
@Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
statsProvider.start();
for (MeterRegistry registry : localRegistry.getRegistries()) {
assertFalse(registry instanceof InfluxMeterRegistry);
assertTrue(registry instanceof StatsdMeterRegistry);
}
statsProvider.close();
assertTrue(0 == localRegistry.getRegistries().size());
}
use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.
the class PrometheusResourceTest method testScrape.
@Test
public void testScrape() throws Exception {
MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_PROMETHEUS, true).build();
@Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
@Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
statsProvider.start();
for (MeterRegistry registry : localRegistry.getRegistries()) {
assertTrue(registry instanceof PrometheusMeterRegistry);
}
assertTrue(statsProvider.prometheusResource().isPresent());
ResourceConfig rc = ResourceConfig.forApplication(new PrometheusApplication(statsProvider));
URI baseUri = UriBuilder.fromUri("http://localhost/").port(TestUtils.getAvailableListenPort()).build();
@Cleanup("shutdown") HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, rc);
Counter c = statsProvider.createStatsLogger("promtest").createCounter("promtestcounter");
c.add(1);
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(baseUri + "prometheus")).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.body().lines().anyMatch(x -> Pattern.matches("promtestcounter.*1\\.0", x)));
server.shutdown();
}
use of io.micrometer.core.instrument.MeterRegistry in project pravega by pravega.
the class PrometheusResourceTest method testStatsProviderNoPrometheus.
@Test
public void testStatsProviderNoPrometheus() {
MetricsConfig appConfig = MetricsConfig.builder().with(MetricsConfig.ENABLE_STATISTICS, true).with(MetricsConfig.ENABLE_STATSD_REPORTER, true).build();
@Cleanup CompositeMeterRegistry localRegistry = new CompositeMeterRegistry();
@Cleanup StatsProvider statsProvider = new StatsProviderImpl(appConfig, localRegistry);
statsProvider.start();
for (MeterRegistry registry : localRegistry.getRegistries()) {
assertFalse(registry instanceof PrometheusMeterRegistry);
}
assertFalse(statsProvider.prometheusResource().isPresent());
statsProvider.close();
}
Aggregations