-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathFluxClientSimpleExample.cs
31 lines (26 loc) · 1.03 KB
/
FluxClientSimpleExample.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
using System;
using System.Threading.Tasks;
using InfluxDB.Client.Flux;
namespace Examples
{
public static class FluxClientSimpleExample
{
public static async Task Main()
{
Console.WriteLine("Start");
var options = new FluxConnectionOptions("http://127.0.0.1:8086", TimeSpan.FromSeconds(20));
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)";
var tables = await client.QueryAsync(fluxQuery);
if (tables != null)
{
foreach (var fluxTable in tables)
foreach (var fluxRecord in fluxTable.Records)
Console.WriteLine(fluxRecord.GetTime() + ": " + fluxRecord.GetValueByKey("_value"));
}
}
}
}