horizonbugs
horizonbugs

Reputation: 11

How to integrate Spring Boot 1.x actuator metrics with io.micrometer? Getting io.micrometer.influx.InfluxRegistry - failed to send metrics error

I have a Rest service implemented with Spring Boot 1.x. I'm trying to send metrics data to an existing influx db by leveraging actuator /metrics. I've found out that Micrometer project (http://micrometer.io/docs/influx#_install) supports Spring Boot integration, but I am unable to find any documentation on how to configure the project to talk to the influx db. E.g: influxdb.connurl, username, dbname etc.

My /metrics works fine. When I make a rest request to my endpoint, because influx db conn is not configured, I'm getting this error:

** [spectator-spring-metrics-publisher-0] WARN io.micrometer.influx.InfluxRegistry - failed to send metrics **

dependencies:

<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>

Is there a documentation somewhere how to write the metrics to influx db? I can write a parser for localhost access file, and install a Telegraf agent to send system metrics, but want to pursue this route first.

Upvotes: 0

Views: 3661

Answers (1)

Feralus
Feralus

Reputation: 167

i am played around with micrometer and influx the other days. First of all you have to set some influx parameters in your application.properties/application.yml file.

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

Make sure the database exists in your influx-db already. I did'nt find a solution to create the database automatically, if it not exists.

You can also create a Bean to configure your Metric-Registry. You can use the registry to add some tags and capture additional metrics.

@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);
    };
}

I don't know if its the best solution, but it works for me. In my maven-file I only use the "micrometer-registry-influx" dependency. After that you should receive metrics about your rest-endpoints in your influx-db.

I hope this helps you a little bit.

Upvotes: 3

Related Questions