提交 297c6a89 编写于 作者: 麦壳饼's avatar 麦壳饼

删除对 InfluxDB 1的支持

上级 e4dd3949
{
"Servers": {
"1": {
"Name": "pgsql",
"Group": "Servers",
"Host": "pgsql",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "postgres",
"SSLMode": "prefer",
"SSLCert": "<STORAGE_DIR>/.postgresql/postgresql.crt",
"SSLKey": "<STORAGE_DIR>/.postgresql/postgresql.key",
"SSLCompression": 0,
"Timeout": 0,
"UseSSHTunnel": 0,
"TunnelPort": "22",
"TunnelAuthentication": 0
}
}
}
......@@ -48,6 +48,9 @@ services:
- influx
links:
- pgsql
- rabbitmq
- mongodb
- influx
ports:
- 2927:80
- 1883:1883
......@@ -55,6 +58,8 @@ services:
- 5683:5683
- 5684:5684
- 502:502
volumes:
- "./appsettings.Production.json:/app/appsettings.Production.json"
networks:
- iotsharp-network
......@@ -113,7 +118,7 @@ services:
INFLUXDB_ORG: "iotsharp"
INFLUXDB_USER: "root"
INFLUXDB_PW: "1-q2-w3-e4-r5-t"
INFLUXDB_RETENTION: "23h60m"
INFLUXDB_RETENTION: "240h60m"
networks:
iotsharp-network:
......
......@@ -127,6 +127,7 @@
<None Remove="healthchecksdb" />
<None Remove="healthchecksdb-shm" />
<None Remove="IoTSharp.xml" />
<_WebToolingArtifacts Remove="Properties\PublishProfiles\registry.hub.docker.com_iotsharp.pubxml" />
<None Include="..\docs\images\96x96.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
......
......@@ -196,11 +196,7 @@ namespace IoTSharp
//"TelemetryStorage": "http://localhost:8086/?org=iotsharp&bucket=iotsharp-bucket&token=iotsharp-token"
services.AddObjectPool(() => InfluxDBClientFactory.Create(Configuration.GetConnectionString("TelemetryStorage")));
break;
case TelemetryStorage.InfluxDBV1:
//docker run -d -p 8083:8083 -p8086:8086 --expose 8090 --expose 8099 --name influxsrv tutum/influxdb
services.AddSingleton<IStorage, InfluxDBV1Storage>();
services.AddObjectPool(() => InfluxDBClientFactory.Create(Configuration.GetConnectionString("TelemetryStorage")));
break;
default:
break;
}
......
using hyjiacan.py4n;
using InfluxDB.Client;
using InfluxDB.Client.Api.Domain;
using InfluxDB.Client.Writes;
using IoTSharp.Data;
using IoTSharp.Dtos;
using IoTSharp.Extensions;
using IoTSharp.Queue;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Options;
using Org.BouncyCastle.Utilities.Encoders;
using Silkier;
using Silkier.EFCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.Storage
{
public class InfluxDBV1Storage : IStorage
{
private readonly AppSettings _appSettings;
private readonly ILogger _logger;
private readonly IServiceScope scope;
private readonly ObjectPool<InfluxDBClient> _taospool;
public InfluxDBV1Storage(ILogger<InfluxDBV1Storage> logger, IServiceScopeFactory scopeFactor
, IOptions<AppSettings> options, ObjectPool<InfluxDBClient> taospool
)
{
_appSettings = options.Value;
_logger = logger;
scope = scopeFactor.CreateScope();
_taospool = taospool;
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId)
{
InfluxDBClient _taos = _taospool.Get();
//string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' group by deviceid,keyname";
List<TelemetryDataDto> dt = null;// SqlToTDD(_taos, sql, "last_row(", ")", string.Empty);
_taospool.Return(_taos);
return Task.FromResult(dt);
}
public Task<List<TelemetryDataDto>> GetTelemetryLatest(Guid deviceId, string keys)
{
InfluxDBClient _taos = _taospool.Get();
IEnumerable<string> kvs = from k in keys
select $" keyname = '{k}' ";
string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) group by deviceid,keyname";
List<TelemetryDataDto> dt = null;// SqlToTDD(_taos, sql, "last_row(", ")", string.Empty);
_taospool.Return(_taos);
return Task.FromResult(dt);
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin)
{
return LoadTelemetryAsync(deviceId, keys, begin, DateTime.Now);
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin, DateTime end)
{
InfluxDBClient _taos = _taospool.Get();
IEnumerable<string> kvs = from k in keys
select $" keyname = '{k}' ";
string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) ";
List<TelemetryDataDto> dt = null;// SQLToDTByDate(begin, end, _taos, sql);
_taospool.Return(_taos);
return Task.FromResult(dt);
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, DateTime begin)
{
return LoadTelemetryAsync(deviceId, begin, DateTime.Now);
}
public Task<List<TelemetryDataDto>> LoadTelemetryAsync(Guid deviceId, DateTime begin, DateTime end)
{
InfluxDBClient _taos = _taospool.Get();
string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}'";
List<TelemetryDataDto> dt = null; //SQLToDTByDate(begin, end, _taos, sql);
_taospool.Return(_taos);
return Task.FromResult(dt);
}
public async Task<bool> StoreTelemetryAsync(RawMsg msg)
{
bool result = false;
try
{
List<PointData> lst = new List<PointData>();
msg.MsgBody.ToList().ForEach(kp =>
{
if (kp.Value != null)
{
TelemetryData tdata = new TelemetryData() { DateTime = DateTime.Now, DeviceId = msg.DeviceId, KeyName = kp.Key, Value_DateTime = new DateTime(1970, 1, 1) };
tdata.FillKVToMe(kp);
var point = PointData.Measurement(nameof(TelemetryData))
.Tag("DeviceId", tdata.DeviceId.ToString());
switch (tdata.Type)
{
case DataType.Boolean:
// point.Field("value_type", "value_boolean");
point= point.Field(tdata.KeyName, tdata.Value_Boolean);
break;
case DataType.String:
//point.Field("value_string", "value_boolean");
point = point.Field(tdata.KeyName, tdata.Value_String);
break;
case DataType.Long:
point = point.Field(tdata.KeyName, tdata.Value_Long);
break;
case DataType.Double:
point = point.Field(tdata.KeyName, tdata.Value_Double);
break;
case DataType.Json:
point = point.Field(tdata.KeyName, tdata.Value_Json);
break;
case DataType.XML:
point = point.Field(tdata.KeyName, tdata.Value_XML);
break;
case DataType.Binary:
point = point.Field(tdata.KeyName, Hex.ToHexString(tdata.Value_Binary));
break;
case DataType.DateTime:
point = point.Field(tdata.KeyName, tdata.Value_DateTime.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);
break;
default:
break;
}
point = point.Timestamp(DateTime.UtcNow, WritePrecision.Ns);
lst.Add(point);
}
});
InfluxDBClient _taos = _taospool.Get();
var writeApi = _taos.GetWriteApiAsync();
await writeApi.WritePointsAsync(lst );
_taospool.Return(_taos);
_logger.LogInformation($"数据入库完成,共数据{lst.Count}条");
}
catch (Exception ex)
{
_logger.LogError(ex, $"{msg.DeviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
}
return result;
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册