219.5. Metric Registry
Camel Metrics 组件默认使用带有 60 秒报告间隔的 Slf4jReporter
的 MetricRegistry
实例。通过提供一个 MetricRegistry
bean,可以将此默认 registry 替换为自定义 registry。如果应用中存在多个 MetricRegistry
Bean,则会使用其名称 metricRegistry
的密钥。
例如,使用 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 = MetricsComponent.METRIC_REGISTRY_NAME) public MetricRegistry getMetricRegistry() { MetricRegistry registry = ...; 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(MetricsComponent.METRIC_REGISTRY_NAME) MetricRegistry registry() { MetricRegistry registry = new MetricRegistry(); // ... return registry; } }