Search code examples
c#grafanainfluxdbmetrics

How can I connect to influxdb v2.4 on .net api with using app metrics library?


Does app metrics .net library support influxdb latest version ? I read documentation of App.Metrics.InfluxDB, but I didn't find nothing. I want to connect influxdb on .net web api with token, but there is no field that I can use. I can't see the bucket name or token field. How can I connect to influxdb v2.4 on .net api with using app metrics library? I want to collect metrics and create dashboards using Grafana, influxdb latest version and App Metrics in .NET Core. Below are the details of App.Metrics.InfluxDB configuation options.

    var filter = new MetricsFilter().WhereType(MetricType.Timer);
    var metrics = new MetricsBuilder()
    .Report.ToInfluxDb(
        options => {
            options.InfluxDb.BaseUri = new Uri("http://127.0.0.1:8086");
            options.InfluxDb.Database = "metricsdatabase";
            options.InfluxDb.Consistenency = "consistency";
            options.InfluxDb.UserName = "admin";
            options.InfluxDb.Password = "password";
            options.InfluxDb.RetentionPolicy = "rp";
            options.InfluxDb.CreateDataBaseIfNotExists = true;
            options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
            options.HttpPolicy.FailuresBeforeBackoff = 5;
            options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
            options.MetricsOutputFormatter = new MetricsInfluxDbLineProtocolOutputFormatter();
            options.Filter = filter;
            options.FlushInterval = TimeSpan.FromSeconds(20);
        })
    .Build();

Solution

  • It doesn't look like they support InfluxDB v2, but you could use the v1 compatibility API in InfluxDB v2 to make it work anyway. See https://docs.influxdata.com/influxdb/v2.4/reference/api/influxdb-1x/ for instructions on setting up username/password authentication and Database/Retention Policy mapping.