using System; using InfluxDB.Client; using InfluxDB.Client.Api.Domain; using OutputServiceTSDB.Models; using OutputServiceTSDB.Utilities; namespace OutputServiceTSDB.InfluxDB { public class InfluxWriter: IDisposable { private readonly char[] Token = EnvironmentVariableConfiguration.InfluxDBToken.ToCharArray(); private InfluxDBClient influxDBClient; public InfluxWriter() { influxDBClient = InfluxDBClientFactory.Create(EnvironmentVariableConfiguration.InfluxDBHost, Token); } public void Write(MeasurementObject measurementObject) { using (var writeApi = influxDBClient.GetWriteApi()) { writeApi.WriteMeasurement(EnvironmentVariableConfiguration.InfluxDBBucket, EnvironmentVariableConfiguration.InfluxDBOrg, WritePrecision.Ns, measurementObject); } } public void Dispose() { influxDBClient.Dispose(); } } }