This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new d841a19942a feat(micrometer): log metrics on shutdown
d841a19942a is described below
commit d841a19942ade85512cc54d6b3f21f09cd539b08
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Mon Mar 2 13:17:31 2026 +0100
feat(micrometer): log metrics on shutdown
Ref CAMEL-23089
---
.../src/main/docs/micrometer.json | 13 ++++++++++
.../metrics/CamelMetricsAutoConfiguration.java | 6 ++++-
.../metrics/CamelMetricsConfiguration.java | 28 +++++++++++++++++++++-
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git
a/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
b/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
index f0828a26a60..f38154a4dce 100644
--- a/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
+++ b/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
@@ -91,6 +91,19 @@
"sourceType":
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration",
"defaultValue": true
},
+ {
+ "name": "camel.metrics.log-metrics-on-shutdown",
+ "type": "java.lang.Boolean",
+ "description": "Log metrics when application is shutting down. (default,
`false`).",
+ "sourceType":
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration",
+ "defaultValue": false
+ },
+ {
+ "name": "camel.metrics.log-metrics-on-shutdown-filters",
+ "type": "java.lang.String",
+ "description": "List of metrics (comma separated) to log when
application is shutting down. You can use `*` character to log any metrics
containing the wildcard, for example `camel.exchanges.*` (default to all
metrics available).",
+ "sourceType":
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration"
+ },
{
"name": "camel.metrics.naming-strategy",
"type": "java.lang.String",
diff --git
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
index 15b2a5a6f00..f12fed7cbe9 100644
---
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
+++
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
@@ -19,7 +19,6 @@ package
org.apache.camel.component.micrometer.springboot.metrics;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.camel.CamelContext;
import
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
-import
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
import
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategyDefault;
import
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategyLegacy;
import
org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
@@ -76,6 +75,11 @@ public class CamelMetricsAutoConfiguration {
MicrometerExchangeEventNotifier notifier = new
MicrometerExchangeEventNotifier();
notifier.setCamelContext(camelContext);
notifier.setMeterRegistry(meterRegistry);
+
notifier.setLogMetricsOnShutdown(configuration.isLogMetricsOnShutdown());
+ if (configuration.getLogMetricsOnShutdownFilters() != null){
+ String[] shutdownFilters =
configuration.getLogMetricsOnShutdownFilters().split(",");
+ notifier.setLogMetricsOnShutdownFilters(shutdownFilters);
+ }
if ("legacy".equalsIgnoreCase(configuration.getNamingStrategy())) {
notifier.setNamingStrategy(new
MicrometerExchangeEventNotifierNamingStrategyLegacy(
configuration.isBaseEndpointUriExchangeEventNotifier()
diff --git
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
index f5ef0ed97ef..71499c70383 100644
---
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
+++
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.micrometer.springboot.metrics;
-import org.apache.camel.spi.Metadata;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "camel.metrics")
@@ -96,6 +95,17 @@ public class CamelMetricsConfiguration {
*/
private boolean enableInstrumentedThreadPoolFactory;
+ /**
+ * Log metrics when application is shutting down. (default, `false`).
+ */
+ private boolean logMetricsOnShutdown = false;
+
+ /**
+ * List of metrics (comma separated) to log when application is shutting
down. You can use `*` character to log any
+ * metrics containing the wildcard, for example `camel.exchanges.*`
(default to all metrics available).
+ */
+ private String logMetricsOnShutdownFilters;
+
public boolean isUriTagEnabled() {
return uriTagEnabled;
}
@@ -183,4 +193,20 @@ public class CamelMetricsConfiguration {
public void setEnableInstrumentedThreadPoolFactory(boolean
enableInstrumentedThreadPoolFactory) {
this.enableInstrumentedThreadPoolFactory =
enableInstrumentedThreadPoolFactory;
}
+
+ public boolean isLogMetricsOnShutdown() {
+ return logMetricsOnShutdown;
+ }
+
+ public void setLogMetricsOnShutdown(boolean logMetricsOnShutdown) {
+ this.logMetricsOnShutdown = logMetricsOnShutdown;
+ }
+
+ public String getLogMetricsOnShutdownFilters() {
+ return logMetricsOnShutdownFilters;
+ }
+
+ public void setLogMetricsOnShutdownFilters(String
logMetricsOnShutdownFilters) {
+ this.logMetricsOnShutdownFilters = logMetricsOnShutdownFilters;
+ }
}