Camel Metrics 구성 요소는 기본적으로 60초 보고 간격이 있는 Slf4jReporter 와 함께 MetricRegistry 인스턴스를 사용합니다. 이 기본 레지스트리는 MetricRegistry 빈을 제공하여 사용자 지정 레지스트리로 교체할 수 있습니다. 애플리케이션에 여러 개의 MetricRegistry 빈이 있는 경우 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;
}
}
@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;
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
또는 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;
}
}
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;
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
Important
MetricRegistry 는 보고를 위해 내부 스레드를 사용합니다. 사용자가 종료를 정리할 수 있도록 DropWizard 3.0.1 버전에 공용 API가 없습니다. 따라서 Camel Metrics 구성 요소를 사용하면 Java classloader 누수가 발생하고 경우에 따라 OutOfMemoryErrors 가 발생합니다.