-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathFluxClientPocoExample.cs
37 lines (33 loc) · 1.22 KB
/
FluxClientPocoExample.cs
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
37
using System;
using System.Threading.Tasks;
using InfluxDB.Client.Flux;
namespace Examples
{
public static class FluxClientPocoExample
{
public static async Task Main()
{
var options = new FluxConnectionOptions("http://127.0.0.1:8086");
using var client = new FluxClient(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)";
////Example of additional result stream processing on client side
await client.QueryAsync<Cpu>(fluxQuery, cpu =>
{
// process the flux query records
Console.WriteLine(cpu.ToString());
},
(error) =>
{
// error handling while processing result
Console.WriteLine(error.ToString());
}, () =>
{
// on complete
Console.WriteLine("Query completed");
});
}
}
}