Once you install InfluxDB, 2 it surfaces a website that includes sample code for various languages. Having created a bucket and a token with RW permissions and selected them, snippets of code with appropriate magic strings are available. Putting them together I have this:
using System;
using System.Threading.Tasks;
using InfluxDB.Client;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Writes;
namespace gen
{
class Program
{
static async Task Main(string[] args)
{
// init
const string token = "uaKktnduBm_ranBVaG3y8vU-AAN ... w==";
const string bucket = "SystemMonitor";
const string org = "pdconsec";
var client = InfluxDBClientFactory.Create("http://10.1.1.182:8086", token.ToCharArray());
// write using data point (doesn't require model class)
var point = PointData
.Measurement("mem")
.Tag("host", "host1")
.Field("used_percent", 23.43234543)
.Timestamp(DateTime.UtcNow, WritePrecision.Ns);
using (var writeApi = client.GetWriteApi())
{
writeApi.WritePoint(bucket, org, point);
}
// Flux query
var query = $"from(bucket: \"{bucket}\") |> range(start: -1h)";
var tables = await client.GetQueryApi().QueryAsync(query, org);
}
}
}
The snippets demonstrate three different ways to write the same datum. All three execute without incident, but without data appearing in the bucket, so I have simplified the code here to just one write method. It runs without incident, but nothing appears in the bucket. Stepping through execution reveals that the Flux query executes returning an empty list of tables.
- Do I need to create something inside a bucket or somehow assign it a structure corresponding to the shape of the data point?
- Is there some kind of save, flush or commit that I have omitted?
- That query looks to me like it means "everything from the named bucket that was logged in the last hour", is that right?