forked from influxdata/influxdb-client-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFluxClientFactoryExample.cs
More file actions
36 lines (32 loc) · 1.2 KB
/
FluxClientFactoryExample.cs
File metadata and controls
36 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Threading.Tasks;
using InfluxDB.Client.Flux;
namespace Examples
{
public static class FluxClientFactoryExample
{
public static async Task Main(string[] args)
{
var options = new FluxConnectionOptions("http://127.0.0.1:8086");
using var fluxClient = FluxClientFactory.Create(options);
var fluxQuery = "from(bucket: \"telegraf\")\n"
+ " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
+ " |> range(start: -1d)"
+ " |> sample(n: 5, pos: 1)";
await fluxClient.QueryAsync(fluxQuery, record =>
{
// process the flux query records
Console.WriteLine(record.GetTime() + ": " + record.GetValue());
},
(error) =>
{
// error handling while processing result
Console.WriteLine(error.ToString());
}, () =>
{
// on complete
Console.WriteLine("Query completed");
});
}
}
}