220.5. Meter Registry
默认情况下,Camel Micrometer 组件会创建一个 SimpleMeterRegistry
实例,主要用于测试。您应当通过提供 MeterRegistry
bean 来定义专用 registry。Micrometer registry 主要决定要使用的后端监控系统。CompositeMeterRegistry
可用于处理多个监控目标。
例如,使用 Spring Java 配置:
@Configuration public static class MyConfig extends SingleRouteCamelConfiguration { @Bean @Override public RouteBuilder route() { return new RouteBuilder() { @Override public void configure() throws Exception { // define Camel routes here } }; } @Bean(name = MicrometerComponent.METRICS_REGISTRY_NAME) public MeterRegistry getMeterRegistry() { CompositeMeterRegistry registry = ...; registry.add(...); // ... return registry; } }
或者使用 CDI:
class MyBean extends RouteBuilder { @Override public void configure() { from("...") // Register the 'my-meter' meter in the MetricRegistry below .to("metrics:meter:my-meter"); } @Produces // If multiple MetricRegistry beans // @Named(MicrometerComponent.METRIC_REGISTRY_NAME) MetricRegistry registry() { CompositeMeterRegistry registry = ...; registry.add(...); // ... return registry; } }