-
Notifications
You must be signed in to change notification settings - Fork 93
/
InfluxDB18Example.cs
44 lines (37 loc) · 1.33 KB
/
InfluxDB18Example.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
38
39
40
41
42
43
44
using System;
using System.Threading.Tasks;
using InfluxDB.Client;
using InfluxDB.Client.Writes;
namespace Examples
{
public class InfluxDB18Example
{
public static async Task Main()
{
const string database = "telegraf";
const string retentionPolicy = "autogen";
using var client = new InfluxDBClient("http://localhost:8086",
"username",
"password",
database,
retentionPolicy);
Console.WriteLine("*** Write Points ***");
using (var writeApi = client.GetWriteApi())
{
var point = PointData.Measurement("mem")
.Tag("host", "host1")
.Field("used_percent", 28.43234543);
writeApi.WritePoint(point);
}
Console.WriteLine("*** Query Points ***");
var query = $"from(bucket: \"{database}/{retentionPolicy}\") |> range(start: -1h)";
var fluxTables = await client.GetQueryApi().QueryAsync(query);
var fluxRecords = fluxTables[0].Records;
fluxRecords.ForEach(record =>
{
Console.WriteLine(
$"{record.GetTime()} {record.GetMeasurement()}: {record.GetField()} {record.GetValue()}");
});
}
}
}