Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
297c6a89
IoTSharp
项目概览
IoTSharp
/
IoTSharp
10 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
297c6a89
编写于
11月 25, 2020
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除对 InfluxDB 1的支持
上级
e4dd3949
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
29 addition
and
166 deletion
+29
-166
Deployments/rabbit_mongo_influx/data/servers.json
Deployments/rabbit_mongo_influx/data/servers.json
+21
-0
Deployments/rabbit_mongo_influx/docker-compose.yml
Deployments/rabbit_mongo_influx/docker-compose.yml
+6
-1
IoTSharp/IoTSharp.csproj
IoTSharp/IoTSharp.csproj
+1
-0
IoTSharp/Startup.cs
IoTSharp/Startup.cs
+1
-5
IoTSharp/Storage/InfluxDBV1Storage.cs
IoTSharp/Storage/InfluxDBV1Storage.cs
+0
-160
未找到文件。
Deployments/rabbit_mongo_influx/data/servers.json
0 → 100644
浏览文件 @
297c6a89
{
"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
}
}
}
Deployments/rabbit_mongo_influx/docker-compose.yml
浏览文件 @
297c6a89
...
...
@@ -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
:
"
2
3
h60m"
INFLUXDB_RETENTION
:
"
2
40
h60m"
networks
:
iotsharp-network
:
...
...
IoTSharp/IoTSharp.csproj
浏览文件 @
297c6a89
...
...
@@ -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>
...
...
IoTSharp/Startup.cs
浏览文件 @
297c6a89
...
...
@@ -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
;
}
...
...
IoTSharp/Storage/InfluxDBV1Storage.cs
已删除
100644 → 0
浏览文件 @
e4dd3949
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录