【问题标题】:How to integrate Spring Boot 1.x actuator metrics with io.micrometer? Getting io.micrometer.influx.InfluxRegistry - failed to send metrics error如何将 Spring Boot 1.x 执行器指标与 io.micrometer 集成?获取 io.micrometer.influx.InfluxRegistry - 未能发送指标错误
【发布时间】:2017-09-21 21:23:15
【问题描述】:

我有一个使用 Spring Boot 1.x 实现的 Rest 服务。我正在尝试通过利用执行器 /metrics 将指标数据发送到现有的流入数据库。我发现 Micrometer 项目 (http://micrometer.io/docs/influx#_install) 支持 Spring Boot 集成,但我找不到任何有关如何配置项目以与 influx db 对话的文档。 例如:influxdb.connurl、用户名、dbname 等。

我的 /metrics 工作正常。当我向端点发出休息请求时,由于未配置 influx db conn,我收到此错误:

** [spectator-spring-metrics-publisher-0] 警告 io.micrometer.influx.InfluxRegistry - 发送指标失败 **

依赖:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>${spring-boot.version}</version>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-spring-legacy</artifactId>
    <version>${micrometer.version}</version>
    </dependency>
 <dependency>
     <groupId>io.micrometer</groupId>
     <artifactId>micrometer-registry-influx</artifactId>
     <version>${micrometer.version}</version>
 </dependency>

是否有关于如何将指标写入 influx db 的文档?我可以为 localhost 访问文件编写一个解析器,并安装一个 Telegraf 代理来发送系统指标,但我想先走这条路线。

【问题讨论】:

    标签: spring spring-boot metrics influxdb micrometer


    【解决方案1】:

    前几天我喜欢玩千分尺并涌入。首先,您必须在 application.properties/application.yml 文件中设置一些流入参数。

      spring:
        metrics:
         influx:
           uri: http://localhost:8086/write 
           enabled: true
           userName: root
           password: root
           step: PT10S
           db:  metrics
    

    确保数据库已经存在于您的 influx-db 中。如果数据库不存在,我没有找到自动创建数据库的解决方案。

    您还可以创建一个 Bean 来配置您的 Metric-Registry。 您可以使用注册表添加一些标签并捕获其他指标。

    @Bean
    MeterRegistryConfigurer configurer() {
        return registry -> {
            registry.config().commonTags("service", "tweets");
            new ClassLoaderMetrics().bindTo(registry);
            new JvmMemoryMetrics().bindTo(registry);
            new JvmGcMetrics().bindTo(registry);
            new ProcessorMetrics().bindTo(registry);
            new JvmThreadMetrics().bindTo(registry);
        };
    }
    

    我不知道它是否是最好的解决方案,但它对我有用。在我的 Maven 文件中,我只使用“micrometer-registry-influx”依赖项。 之后,您应该会在 influx-db 中收到有关休息端点的指标。

    希望对你有所帮助。

    【讨论】:

    • 和@Feralus 一样,我可以将指标添加到现有基础,但不能即时创建数据库。从source code 的快速概览来看,发送CREATE DATABASE 查询时似乎未发送用户凭据。
    • 你可以设置management.metrics.export.influx.auto-create-db=true创建influx数据库,如果它死不存在。
    猜你喜欢
    • 2018-11-29
    • 2020-04-20
    • 2022-10-14
    • 1970-01-01
    • 2016-07-24
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    相关资源
    最近更新 更多