如何使用 /actuator/prometheus 的 Micrometer 格式将 metrics:timer:simple.timer 等 Apache Camel 指标输出到 Prometheus

How to output Apache Camel metrics like metrics:timer:simple.timer to Prometheus using Micrometer format with /actuator/prometheus

基于Camel's metrics documentation,我想在一条路线内计量 2 个不同的计时器:

  @Override
    public void configure() {
        from(
                getMqttRouteConfiguration(
                        sourceId, mqttHost, mqttTopic, mqttPort, mqttProtocol, authenticated,
                        username, password, mqttVersion, maxReadRate, qualityOfService
                )
        )
                .to("metrics:timer:simple.timer1?action=start") //here starts the first one
                .to("log:camel.proxy?level=INFO&groupInterval=500000")
                .to("metrics:counter:simple.counter")
                .to(String.format("kafka:%s?brokers=%s", sourceId, kafkaBrokerUrls))
                .to("metrics:timer:simple.timer1?action=stop") //here ends the first one
                .to("metrics:timer:simple.timer2?action=start") //here starts the second one
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setBody(exchange.getIn().getBody(String.class));
                        exchange.getIn().setHeader("CamelCacheKey", sourceId);
                        exchange.getIn().setHeader("CamelCacheOperation", "Update");
                    }
                })
                .to(String.format("cache://%s?maxElementsInMemory=10&eternal=true", sourceId))
                .to("metrics:timer:simple.timer2?action=stop") //here ends the second one
                .routeId(sourceId);
    }

即从路线的两个不同部分取 2 个计时器,而不是像

这样的整个路线统计
CamelRoutePolicy_seconds_count{camelContext="camel-1",failed="false",routeId="ESP_01.Handle_Movement",serviceName="MicrometerRoutePolicyService",} 137.0
CamelRoutePolicy_seconds_sum{camelContext="camel-1",failed="false",routeId="ESP_01.Handle_Movement",serviceName="MicrometerRoutePolicyService",} 1.200024598

因为它是为整条路线自动计算的。 Micrometer 格式指标输出到 /actuator/prometheus 以获得 CamelRoutePolicy_seconds_ 的设置取自这个问题:

但是,我的预期是客户指标 metrics:timer:simple.timer2metrics:timer:simple.timer1 也会出现在这里并显示在 CamelRoutePolicy_seconds_

但它不存在。我应该设置什么才能得到它?

长话短说:Apache Camel 的 Metrics component is not the same as Micrometer

我需要千分尺。因此,在所有路线中,我必须将 metrics: 替换为 micrometer: 并且一切正常。还请考虑依赖项(看起来两者都需要):

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-micrometer-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-micrometer</artifactId>
        <version>${camel.version}</version>
    </dependency>