public void Dispose() { _influxDbClient.GetDeleteApi() .Delete(DateTime.UtcNow.AddYears(-1), DateTime.UtcNow, "", _influxDbOptions.Bucket, _influxDbOptions.Organization); _influxDbClient?.Dispose(); }
public static async Task Example(InfluxDBClient influxDB) { var organizationClient = influxDB.GetOrganizationsApi(); var medicalGMBH = await organizationClient .CreateOrganizationAsync("Medical Corp " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture)); // // Create New Bucket with retention 1h // var temperatureBucket = await influxDB.GetBucketsApi().CreateBucketAsync("temperature-sensors", medicalGMBH.Id); // // Add Permissions to read and write to the Bucket // var resource = new PermissionResource { Type = PermissionResource.TypeEnum.Buckets, OrgID = medicalGMBH.Id, Id = temperatureBucket.Id }; var readBucket = new Permission { Resource = resource, Action = Permission.ActionEnum.Read }; var writeBucket = new Permission { Resource = resource, Action = Permission.ActionEnum.Write }; var authorization = await influxDB.GetAuthorizationsApi() .CreateAuthorizationAsync(medicalGMBH, new List <Permission> { readBucket, writeBucket }); Console.WriteLine($"The token to write to temperature-sensors bucket is: {authorization.Token}"); influxDB.Dispose(); // // Create new client with specified authorization token // influxDB = InfluxDBClientFactory.Create("http://localhost:8086", authorization.Token); var writeOptions = WriteOptions .CreateNew() .BatchSize(5000) .FlushInterval(1000) .JitterInterval(1000) .RetryInterval(5000) .Build(); // // Write data // using (var writeClient = influxDB.GetWriteApi(writeOptions)) { // // Write by POCO // var temperature = new Temperature { Location = "south", Value = 62D, Time = DateTime.UtcNow }; writeClient.WriteMeasurement("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, temperature); // // Write by Point // var point = PointData.Measurement("temperature") .Tag("location", "west") .Field("value", 55D) .Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns); writeClient.WritePoint("temperature-sensors", medicalGMBH.Id, point); // // Write by LineProtocol // var record = "temperature,location=north value=60.0"; writeClient.WriteRecord("temperature-sensors", medicalGMBH.Id, WritePrecision.Ns, record); writeClient.Flush(); Thread.Sleep(2000); } // // Read data // var fluxTables = await influxDB.GetQueryApi().QueryAsync("from(bucket:\"temperature-sensors\") |> range(start: 0)", medicalGMBH.Id); fluxTables.ForEach(fluxTable => { var fluxRecords = fluxTable.Records; fluxRecords.ForEach(fluxRecord => { Console.WriteLine($"{fluxRecord.GetTime()}: {fluxRecord.GetValue()}"); }); }); // // Delete data // await influxDB.GetDeleteApi().Delete(DateTime.UtcNow.AddMinutes(-1), DateTime.Now, "", temperatureBucket, medicalGMBH); influxDB.Dispose(); }