Sample code for connection using C sharp

Download nuget package for working with influx: https://www.nuget.org/packages/InfluxDB.Client/

After importing nuget package into project we can access database using the following snippet:

var influxDBClient = InfluxDBClientFactory.Create(url, token);
  • We obtain url and token using steps in connection.

To query influx database use scripting language flux.

Sample of getting data about live sessions:

private static async Task<List<FluxTable>> GetFluxTables(int companyId, string measurement)
    var flux = "from(bucket:\"mluvii_realtime\") " +
               "|> range(start: -1h)" +
              $"|> filter(fn: (r) => r[\"_measurement\"] == \"{measurement}\")" +
               "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";
     return await influxDBClient.GetQueryApi().QueryAsync(flux, org: $"company_{companyId}");
  • Bucket is always the same "mluvii_realtime"

  • CompanyId is company ID

  • Measurement is combination of metric's name and a suffix which is configured in the metric's settings in mluvii.

Example: running_sessions_demo, where "running_sessions" is the name of the metric and "demo" is configured in mluvii

Next steps?

Last updated