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

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

Binary file not shown.

Binary file not shown.

View File

@ -26,7 +26,7 @@ namespace OutputServiceTSDB.Controllers
var rng = new Random(); var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new ApiObject return Enumerable.Range(1, 5).Select(index => new ApiObject
{ {
Date = DateTime.Now.AddDays(index) Probability = 0.5
}) })
.ToArray(); .ToArray();
} }

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;
}
}

View File

@ -4,12 +4,20 @@ namespace OutputServiceTSDB.Models
{ {
public class ApiObject public class ApiObject
{ {
public DateTime Date { get; set; }
public string Tag { get; set; } public string Tag { get; set; }
public bool Decision { get; set; } private double _probability;
public double Confidence { get; set; } 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;
}
}
} }
} }

View File

@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="InfluxDB.Client" Version="1.6.0" /> <PackageReference Include="InfluxDB.Client" Version="1.6.0" />
<PackageReference Include="InfluxDB.Client.Flux" Version="1.6.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="RabbitMQ.Client" Version="5.1.2" /> <PackageReference Include="RabbitMQ.Client" Version="5.1.2" />
<PackageReference Include="Sentry" Version="2.1.1" /> <PackageReference Include="Sentry" Version="2.1.1" />

View File

@ -42,6 +42,10 @@
"target": "Package", "target": "Package",
"version": "[1.6.0, )" "version": "[1.6.0, )"
}, },
"InfluxDB.Client.Flux": {
"target": "Package",
"version": "[*, )"
},
"Microsoft.VisualStudio.Azure.Containers.Tools.Targets": { "Microsoft.VisualStudio.Azure.Containers.Tools.Targets": {
"target": "Package", "target": "Package",
"version": "[1.10.8, )" "version": "[1.10.8, )"
@ -56,7 +60,7 @@
}, },
"Sentry.AspNetCore": { "Sentry.AspNetCore": {
"target": "Package", "target": "Package",
"version": "[*, )" "version": "[2.1.1, )"
} }
}, },
"imports": [ "imports": [

View File

@ -48,6 +48,18 @@
"lib/netstandard2.0/InfluxDB.Client.Core.dll": {} "lib/netstandard2.0/InfluxDB.Client.Core.dll": {}
} }
}, },
"InfluxDB.Client.Flux/1.6.0": {
"type": "package",
"dependencies": {
"InfluxDB.Client.Core": "1.6.0"
},
"compile": {
"lib/netstandard2.0/InfluxDB.Client.Flux.dll": {}
},
"runtime": {
"lib/netstandard2.0/InfluxDB.Client.Flux.dll": {}
}
},
"JsonSubTypes/1.5.2": { "JsonSubTypes/1.5.2": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -1662,6 +1674,19 @@
"lib/netstandard2.0/InfluxDB.Client.Core.dll" "lib/netstandard2.0/InfluxDB.Client.Core.dll"
] ]
}, },
"InfluxDB.Client.Flux/1.6.0": {
"sha512": "Fjs5SOlPfAyjSnWkPDxCluDO8t2nIlECrUMdWKZ7Pdtn9mr81kizLzBPIiRw4odQ4zWJJrfSa1v0eQ998isMQw==",
"type": "package",
"path": "influxdb.client.flux/1.6.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"influxdata.jpg",
"influxdb.client.flux.1.6.0.nupkg.sha512",
"influxdb.client.flux.nuspec",
"lib/netstandard2.0/InfluxDB.Client.Flux.dll"
]
},
"JsonSubTypes/1.5.2": { "JsonSubTypes/1.5.2": {
"sha512": "Lu1fbpVYMDl45cz8Y0cH7MTjIN0dDhjg2srkbIJ7fjHvGepfzgKCf7WC5qp2vCxVZfNDeAcS1YAJZELhUFVPsw==", "sha512": "Lu1fbpVYMDl45cz8Y0cH7MTjIN0dDhjg2srkbIJ7fjHvGepfzgKCf7WC5qp2vCxVZfNDeAcS1YAJZELhUFVPsw==",
"type": "package", "type": "package",
@ -5731,10 +5756,11 @@
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
".NETCoreApp,Version=v3.1": [ ".NETCoreApp,Version=v3.1": [
"InfluxDB.Client >= 1.6.0", "InfluxDB.Client >= 1.6.0",
"InfluxDB.Client.Flux >= *",
"Microsoft.VisualStudio.Azure.Containers.Tools.Targets >= 1.10.8", "Microsoft.VisualStudio.Azure.Containers.Tools.Targets >= 1.10.8",
"RabbitMQ.Client >= 5.1.2", "RabbitMQ.Client >= 5.1.2",
"Sentry >= 2.1.1", "Sentry >= 2.1.1",
"Sentry.AspNetCore >= *" "Sentry.AspNetCore >= 2.1.1"
] ]
}, },
"packageFolders": { "packageFolders": {
@ -5778,6 +5804,10 @@
"target": "Package", "target": "Package",
"version": "[1.6.0, )" "version": "[1.6.0, )"
}, },
"InfluxDB.Client.Flux": {
"target": "Package",
"version": "[*, )"
},
"Microsoft.VisualStudio.Azure.Containers.Tools.Targets": { "Microsoft.VisualStudio.Azure.Containers.Tools.Targets": {
"target": "Package", "target": "Package",
"version": "[1.10.8, )" "version": "[1.10.8, )"
@ -5792,7 +5822,7 @@
}, },
"Sentry.AspNetCore": { "Sentry.AspNetCore": {
"target": "Package", "target": "Package",
"version": "[*, )" "version": "[2.1.1, )"
} }
}, },
"imports": [ "imports": [

View File

@ -1,12 +1,13 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "a6+SV/54J2AISt6d5A/IXuu4A94oTK197hAEYN1M6b9DqJet88JoTE6GeqofcnlF2D3CSw/jUx02OM/VvrU/sw==", "dgSpecHash": "8IABVsx3GAd39YhSptWgfKeaISUbm+vl7fpUGCskZAdvjzJhPj6u3gnGlscTFyKDBbXqEG6VP54P6NIFIudv7w==",
"success": true, "success": true,
"projectFilePath": "C:\\Users\\Torma Kristóf\\source\\repos\\output-service-tsdb\\OutputServiceTSDB.csproj", "projectFilePath": "C:\\Users\\Torma Kristóf\\source\\repos\\output-service-tsdb\\OutputServiceTSDB.csproj",
"expectedPackageFiles": [ "expectedPackageFiles": [
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\csvhelper\\8.1.1\\csvhelper.8.1.1.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\csvhelper\\8.1.1\\csvhelper.8.1.1.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\influxdb.client\\1.6.0\\influxdb.client.1.6.0.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\influxdb.client\\1.6.0\\influxdb.client.1.6.0.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\influxdb.client.core\\1.6.0\\influxdb.client.core.1.6.0.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\influxdb.client.core\\1.6.0\\influxdb.client.core.1.6.0.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\influxdb.client.flux\\1.6.0\\influxdb.client.flux.1.6.0.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\jsonsubtypes\\1.5.2\\jsonsubtypes.1.5.2.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\jsonsubtypes\\1.5.2\\jsonsubtypes.1.5.2.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\microsoft.csharp\\4.4.0\\microsoft.csharp.4.4.0.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\microsoft.csharp\\4.4.0\\microsoft.csharp.4.4.0.nupkg.sha512",
"C:\\Users\\Torma Kristóf\\.nuget\\packages\\microsoft.extensions.configuration\\3.0.0\\microsoft.extensions.configuration.3.0.0.nupkg.sha512", "C:\\Users\\Torma Kristóf\\.nuget\\packages\\microsoft.extensions.configuration\\3.0.0\\microsoft.extensions.configuration.3.0.0.nupkg.sha512",