added influxdb stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-04-08 02:58:29 +02:00
parent 4b993ee5e7
commit 825cd27f3c
14 changed files with 158 additions and 9 deletions

45
InfluxDB/InfluxReader.cs Normal file
View File

@ -0,0 +1,45 @@
using System;
using InfluxDB.Client.Flux;
namespace OutputServiceTSDB.InfluxDB
{
public class InfluxReader
{
private readonly char[] Token = "".ToCharArray();
public InfluxReader()
{
//
// TODO: Add constructor logic here
//
}
public MeasurementObject Read()
{
var fluxClient = FluxClientFactory.Create("http://localhost:8086/");
var fluxQuery = "from(bucket: \"telegraf\")\n"
+ " |> filter(fn: (r) => (r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_system\"))"
+ " |> range(start: -1d)"
+ " |> sample(n: 5, pos: 1)";
fluxClient.QueryAsync(fluxQuery, (cancellable, record) =>
{
// process the flux query records
Console.WriteLine(record.GetTime() + ": " + record.GetValue());
},
(error) =>
{
// error handling while processing result
Console.WriteLine(error.ToString());
}, () =>
{
// on complete
Console.WriteLine("Query completed");
}).GetAwaiter().GetResult();
return new MeasurementObject { DeviceID = "south", Probability = 0.5, Time = DateTime.UtcNow };
}
}
}

26
InfluxDB/InfluxWriter.cs Normal file
View File

@ -0,0 +1,26 @@
using System;
using InfluxDB.Client;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Core;
using InfluxDB.Client.Writes;
namespace OutputServiceTSDB.InfluxDB
{
public class InfluxWriter
{
private readonly char[] Token = "".ToCharArray();
public void Write(MeasurementObject measurementObject)
{
var influxDBClient = InfluxDBClientFactory.Create("http://localhost:9999", Token);
using (var writeApi = influxDBClient.GetWriteApi())
{
var measurement = new MeasurementObject { DeviceID = "south", Probability = 0.5, Time = DateTime.UtcNow };
writeApi.WriteMeasurement("bucket_name", "org_id", WritePrecision.Ns, measurement);
}
influxDBClient.Dispose();
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using InfluxDB.Client;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Core;
using InfluxDB.Client.Writes;
namespace OutputServiceTSDB.InfluxDB
{
[Measurement("temperature")]
public class MeasurementObject
{
[Column("deviceid", IsTag = true)]
public string DeviceID { get; set; }
private double _probability;
[Column("probability")]
public double Probability
{
get => _probability;
set
{
if (value > 1.0 || value < 0.0)
throw new ArgumentOutOfRangeException(
$"{nameof(value)} must be between 0 and 1.");
else
_probability = value;
}
}
[Column(IsTimestamp = true)] public DateTime Time;
}
}