Skip to content

Commit

Permalink
Enable mongodb micrometer metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vkn committed Dec 9, 2024
1 parent b9de708 commit e3d1e69
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ AdditionalIndexedClassesBuildItem includeMongoCommandListener(MongoClientBuildTi
return new AdditionalIndexedClassesBuildItem();
}

@BuildStep
AdditionalIndexedClassesBuildItem includeMongoCommandMetricListener(
MongoClientBuildTimeConfig buildTimeConfig,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
return metricsCapability
.filter(cap -> buildTimeConfig.metricsEnabled && cap.metricsSupported(MetricsFactory.MICROMETER))
.map(supported -> new AdditionalIndexedClassesBuildItem(
MongoClientRecorder.getMicrometerCommandListenerClassName()))
.orElseGet(AdditionalIndexedClassesBuildItem::new);
}

@BuildStep
public void registerDnsProvider(BuildProducer<NativeImageResourceBuildItem> nativeProducer) {
nativeProducer.produce(new NativeImageResourceBuildItem("META-INF/services/" + DnsClientProvider.class.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.mongodb.metrics;

import jakarta.inject.Inject;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener;

public class MicrometerCommandListener extends MongoMetricsCommandListener {
@Inject
public MicrometerCommandListener(MeterRegistry registry) {
super(registry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.mongodb.event.ConnectionPoolListener;

import io.quarkus.arc.Arc;
import io.quarkus.mongodb.metrics.MicrometerCommandListener;
import io.quarkus.mongodb.metrics.MicrometerConnectionPoolListener;
import io.quarkus.mongodb.metrics.MongoMetricsConnectionPoolListener;
import io.quarkus.mongodb.reactive.ReactiveMongoClient;
Expand Down Expand Up @@ -99,6 +100,10 @@ public ConnectionPoolListener get() {
};
}

public static String getMicrometerCommandListenerClassName() {
return MicrometerCommandListener.class.getName();
}

public Supplier<ConnectionPoolListener> createMPMetricsConnectionPoolListener() {
return new Supplier<ConnectionPoolListener>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ private void callPersonEndpoint(String endpoint) {
.when().get("/q/metrics")
.then()
.statusCode(200)
.body(CoreMatchers.containsString("mongodb_driver_commands_seconds_max"))
.body(CoreMatchers.containsString("mongodb_driver_pool_checkedout"))
.body(CoreMatchers.containsString("mongodb_driver_pool_size"))
.body(CoreMatchers.containsString("mongodb_driver_pool_waitqueuesize"));
Expand Down

0 comments on commit e3d1e69

Please sign in to comment.