static async Task Simple() { var points = new InfluxPoints() .Add(new InfluxPoint("ticketsold").AddTag("seller", "1").AddTag("cur", "SEK").AddField("amt", 150.0).AddField("fee", 50.0)) //TimeStamp is assigned in Influx .Add(new InfluxPoint("ticketsold").AddTag("seller", "1").AddTag("cur", "USD").AddField("amt", 10.0).AddField("fee", 2.5).AddTimeStamp()) .Add(new InfluxPoint("ticketsold").AddTag("seller", "2").AddTag("cur", "USD").AddField("amt", 10.0).AddField("fee", 2.5).AddTimeStamp(DateTime.Now)) //Is converted to nanoseconds since Epoch (UTC) .Add(new InfluxPoint("ticketsold").AddTag("seller", "1").AddTag("cur", "EUR").AddField("amt", 9.5).AddField("fee", 5.0).AddTimeStamp(TimeStampResolutions.Nanoseconds)) .Add(new InfluxPoint("ticketsold").AddTag("seller", "2").AddTag("cur", "SEK").AddField("amt", 225.5).AddField("fee", 50.0).AddTimeStamp(TimeStampResolutions.Microseconds)) .Add(new InfluxPoint("ticketsold").AddTag("seller", "3").AddTag("cur", "SEK").AddField("amt", 110.0).AddField("fee", 30.0).AddTimeStamp(TimeStampResolutions.Milliseconds)) .Add(new InfluxPoint("ticketsold").AddTag("seller", "3").AddTag("cur", "SEK").AddField("amt", 2350.0).AddField("fee", 10.0).AddTimeStamp(TimeStampResolutions.Seconds)) .Add(new InfluxPoint("ticketsold").AddTag("seller", "2").AddTag("cur", "EUR").AddField("amt", 51.8).AddField("fee", 5.0).AddTimeStamp(TimeStampResolutions.Minutes)) .Add(new InfluxPoint("ticketsold").AddTag("seller", "1").AddTag("cur", "USD").AddField("amt", 1.0).AddField("fee", 1.0).AddTimeStamp(TimeStampResolutions.Hours)); using (var client = new InfluxDbClient("http://192.168.1.176:9086")) { //configure write options on client (if you want) client.DefaultWriteOptions .SetRetentionPolicy("test") .SetTimeStampPrecision(TimeStampPrecision.Minutes) .SetConsistency(Consistency.Quorum); await client.CreateDatabaseAsync("mydb"); await client.WriteAsync("mydb", points); //specific options can be passed var writeOptions = new WriteOptions() .SetConsistency(Consistency.Any); await client.WriteAsync("mydb", points, writeOptions); } }
protected InfluxDbClient(HttpRequester requester) { Ensure.That(requester, nameof(requester)).IsNotNull(); Requester = requester; InfluxPointsSerializer = new LineProtocolInfluxPointsSerializer(); DefaultWriteOptions = CreateDefaultWriteOptions(); WriteOptionsUrlArgsBuilder = new WriteOptionsUrlArgsBuilder(); }
protected virtual HttpRequest CreateWritePointsRequest(string databaseName, InfluxPoints points, WriteOptions options = null) { var bytesContent = GetBytesContent(points); var writeOptionUrlArgs = WriteOptionsUrlArgsBuilder.Build(options ?? DefaultWriteOptions); return new HttpRequest(HttpMethod.Post, $"write?db={UrlEncoder.Encode(databaseName)}{writeOptionUrlArgs}") .WithContent(bytesContent); }
public async Task WriteAsync(string databaseName, InfluxPoints points, WriteOptions options = null) { ThrowIfDisposed(); Ensure.That(databaseName, nameof(databaseName)).IsNotNullOrWhiteSpace(); Ensure.That(points, nameof(points)).IsNotNull(); Ensure.That(points.IsEmpty, nameof(points)).WithExtraMessageOf(() => "Can not write empty points collections.").IsFalse(); var request = CreateWritePointsRequest(databaseName, points, options); var response = await Requester.SendAsync(request).ForAwait(); EnsureSuccessful(response); }