fix influxdb
This commit is contained in:
parent
921508ebd2
commit
52b76b3022
@ -260,7 +260,10 @@ handle_event(cast, {handle, {data, Data}}, session, State = #state{uuid = UUID,
|
||||
NTags = with_device_uuid(Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName}, Info),
|
||||
|
||||
%% 按照设备的uuid进行分组
|
||||
Points = lists:map(fun(Fields) -> influx_point:new(RouterUUID, NTags, Fields, Timestamp) end, FieldsList),
|
||||
Points = lists:map(fun(Fields) ->
|
||||
NFields = convert_fields(Fields),
|
||||
influx_point:new(RouterUUID, NTags, NFields, Timestamp)
|
||||
end, FieldsList),
|
||||
Precision = influx_client:get_precision(Timestamp),
|
||||
|
||||
poolboy:transaction(influx_pool, fun(Pid) -> influx_client:write(Pid, <<"metric">>, <<"nannong">>, Precision, Points) end);
|
||||
@ -378,6 +381,11 @@ code_change(_OldVsn, StateName, State = #state{}, _Extra) ->
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
|
||||
convert_fields(#{<<"key">> := Key, <<"value">> := Value, <<"unit">> := Unit}) ->
|
||||
#{Key => jiffy:encode(#{<<"value">> => Value, <<"unit">> := Unit}, [force_utf8])};
|
||||
convert_fields(#{<<"key">> := Key, <<"value">> := Value}) ->
|
||||
#{Key => Value}.
|
||||
|
||||
%% 获取到分发的路由
|
||||
router_uuid(#{<<"device_uuid">> := DeviceUUID}, _) when is_binary(DeviceUUID), DeviceUUID /= <<>> ->
|
||||
DeviceUUID;
|
||||
@ -389,3 +397,5 @@ with_device_uuid(Tags, #{<<"device_uuid">> := DeviceUUID}) when DeviceUUID /= <<
|
||||
Tags#{<<"device_uuid">> => DeviceUUID};
|
||||
with_device_uuid(Tags, _) ->
|
||||
Tags.
|
||||
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
]
|
||||
},
|
||||
|
||||
%% influxdb数据库配置
|
||||
%% influxdb数据库配置, 测试环境的: 用户名: iot; password: password1234
|
||||
{influx_pool,
|
||||
[{size, 100}, {max_overflow, 200}, {worker_module, influx_client}],
|
||||
[
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user