Configuring Micrometer.io to use InfluxDB Cloud

I have a Spring Boot application and would like to use InfluxDB Cloud to store application metrics. Facade Micrometer seems a popular choice and has instructions for connection to an Influx DB server; https://micrometer.io/docs/registry/influx. The configuration options include uri, db, user-name and password. Influx DB Cloud configuration options are url, organisation id, bucket and access token. Are these directly substitutable? Please could someone point me to documentation or an example of configuring Micrometer to use InfluxDB Cloud?

Hi @NickDarlow,

currently the Micrometer doesn’t support InfluxDB v2 out of box. There is an issue about it - https://github.com/micrometer-metrics/micrometer/issues/1974. Could you add a comment there?

It will be help us to escalate our PR with InfluxDB v2 supports - https://github.com/micrometer-metrics/micrometer/pull/2113.

I will try prepare a workaround for you… stay tuned :wink:

Regards

Thanks @bednar. I’ve commented on your PR as requested.

Thanks @NickDarlow for comment.

I’ve prepared an example how to use a current version of Spring Boot to sent metrics into the InfluxDB v2.

We had to use a custom HttpSender to add required parameters into a HTTP request:

Custom HttpSender

package io.micrometer.boot2.samples;

import io.micrometer.boot2.samples.components.PersonController;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.OkHttpSender;
import io.micrometer.influx.InfluxConfig;
import io.micrometer.influx.InfluxMeterRegistry;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(scanBasePackageClasses = PersonController.class)
@EnableScheduling
public class InfluxSample {
    public static void main(String[] args) {
        new SpringApplicationBuilder(InfluxSample.class).profiles("influx").run(args);
    }

    @Value("${management.metrics.export.influx.org}")
    private String org;

    @Value("${management.metrics.export.influx.bucket}")
    private String bucket;

    @Value("${management.metrics.export.influx.token}")
    private String token;

    @Bean
    public InfluxMeterRegistry influxMeterRegistry(InfluxConfig influxConfig, Clock clock) {

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(chain -> {
            Request original = chain.request();

            // skip others than write
            if (!original.url().pathSegments().contains("write")) {
                 return  chain.proceed(original);
            }

            HttpUrl url = original.url()
                    .newBuilder()
                    .removePathSegment(0)
                    .addEncodedPathSegments("api/v2/write")
                    .removeAllQueryParameters("db")
                    .removeAllQueryParameters("consistency")
                    .addQueryParameter("org", org)
                    .addQueryParameter("bucket", bucket)
                    .build();

            Request request = original.newBuilder()
                    .url(url)
                    .header("Authorization", "Token " + token)
                    .build();

            return chain.proceed(request);
        });

        return InfluxMeterRegistry.builder(influxConfig)
                .clock(clock)
                .httpClient(new OkHttpSender(httpClient.build()))
                .build();
    }
}

Application configuration

management.metrics.export:
  influx:
    enabled: true
    step: PT10S
    readTimeout: PT30S
    batchSize: 20000
    uri: "http://localhost:9999"
    org: "my-org"
    bucket: "my-bucket"
    token: "my-token"
1 Like

Thanks very much for your assistance @bednar :+1:

You are welcome :handshake:

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.