fix
This commit is contained in:
parent
772d0fbb3f
commit
8ce5080566
76407
apps/iot/priv/global.log-2024-01-12.log
Normal file
76407
apps/iot/priv/global.log-2024-01-12.log
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,7 @@
|
||||
%% API
|
||||
-export([start_link/0]).
|
||||
-export([get_pid/0, forward/3, get_stat/0]).
|
||||
-export([parse_json_file/0, export/0]).
|
||||
|
||||
%% gen_statem callbacks
|
||||
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
|
||||
@ -40,6 +41,34 @@
|
||||
queue = queue:new()
|
||||
}).
|
||||
|
||||
export() ->
|
||||
Lines = parse_json_file(),
|
||||
[begin
|
||||
case catch jiffy:decode(Line, [return_maps]) of
|
||||
M when is_map(M) ->
|
||||
export0(M);
|
||||
Error ->
|
||||
lager:notice("invalid data: ~p, error: ~p", [Line, Error])
|
||||
end
|
||||
end || Line <- Lines].
|
||||
|
||||
export0(Fields0 = #{<<"device_uuid">> := DeviceUUID, <<"timestamp">> := Timestamp}) ->
|
||||
Fields = lists:foldl(fun(Key, M) -> maps:remove(Key, M) end, Fields0, [<<"device_uuid">>]),
|
||||
%% 查找终端设备对应的点位信息
|
||||
case redis_client:hget(DeviceUUID, <<"location_code">>) of
|
||||
{ok, undefined} ->
|
||||
lager:warning("[iot_host] the north_data hget location_code, uuid: ~p, not found, fields: ~p", [DeviceUUID, Fields]);
|
||||
{ok, LocationCode} when is_binary(LocationCode) ->
|
||||
iot_zd_endpoint:forward(LocationCode, [Fields], Timestamp);
|
||||
{error, Reason} ->
|
||||
lager:warning("[iot_host] the north_data hget location_code uuid: ~p, get error: ~p, fields: ~p", [DeviceUUID, Reason, Fields])
|
||||
end.
|
||||
|
||||
parse_json_file() ->
|
||||
File = code:priv_dir(iot) ++ "/global.log-2024-01-12.log",
|
||||
{ok, Content} = file:read_file(File),
|
||||
binary:split(Content, <<$\n>>, [global, trim]).
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
%%%===================================================================
|
||||
|
||||
@ -38,12 +38,12 @@ init([]) ->
|
||||
}
|
||||
],
|
||||
|
||||
{ok, {SupFlags, pools() ++ Specs}}.
|
||||
{ok, {SupFlags, pools() ++ Specs}}.
|
||||
|
||||
%% internal functions
|
||||
|
||||
pools() ->
|
||||
{ok, Pools} = application:get_env(iot, pools),
|
||||
lists:map(fun({Name, PoolArgs, WorkerArgs}) ->
|
||||
poolboy:child_spec(Name, [{name, {local, Name}}|PoolArgs], WorkerArgs)
|
||||
end, Pools).
|
||||
poolboy:child_spec(Name, [{name, {local, Name}}|PoolArgs], WorkerArgs)
|
||||
end, Pools).
|
||||
@ -54,21 +54,6 @@
|
||||
]},
|
||||
|
||||
{pools, [
|
||||
%% mysql连接池配置
|
||||
{mysql_iot,
|
||||
[{size, 10}, {max_overflow, 20}, {worker_module, mysql}],
|
||||
[
|
||||
{host, {39, 98, 184, 67}},
|
||||
{port, 3306},
|
||||
{user, "nannonguser"},
|
||||
{connect_mode, lazy},
|
||||
{keep_alive, true},
|
||||
{password, "nannong@Fe7w"},
|
||||
{database, "nannong"},
|
||||
{queries, [<<"set names utf8">>]}
|
||||
]
|
||||
},
|
||||
|
||||
%% redis连接池
|
||||
{redis_pool,
|
||||
[{size, 10}, {max_overflow, 20}, {worker_module, eredis}],
|
||||
@ -77,18 +62,7 @@
|
||||
{port, 26379},
|
||||
{database, 1}
|
||||
]
|
||||
},
|
||||
|
||||
%% influxdb数据库配置, 测试环境的: 用户名: iot; password: password1234
|
||||
{influx_pool,
|
||||
[{size, 100}, {max_overflow, 200}, {worker_module, influx_client}],
|
||||
[
|
||||
{host, "39.98.184.67"},
|
||||
{port, 8086},
|
||||
{token, <<"IUQ04qecTie7LSuX1EDFBeqspClOdoRBfmXDQxhoEjiJFeW8M-Ui66t981YvviI5qOBpf_ZLgJlBx7nid2lyJQ==">>}
|
||||
]
|
||||
}
|
||||
|
||||
]}
|
||||
|
||||
]},
|
||||
|
||||
@ -42,22 +42,13 @@
|
||||
{pool_size, 10}
|
||||
]},
|
||||
|
||||
{pools, [
|
||||
%% mysql连接池配置
|
||||
{mysql_iot,
|
||||
[{size, 10}, {max_overflow, 20}, {worker_module, mysql}],
|
||||
[
|
||||
{host, {172, 30, 6, 182}},
|
||||
{port, 3306},
|
||||
{user, "nannonguser"},
|
||||
{connect_mode, lazy},
|
||||
{keep_alive, true},
|
||||
{password, "nannong@Fe7w"},
|
||||
{database, "nannong"},
|
||||
{queries, [<<"set names utf8">>]}
|
||||
]
|
||||
},
|
||||
{influxdb, [
|
||||
{host, "172.19.0.4"},
|
||||
{port, 8086},
|
||||
{token, <<"A-ZRjqMK_7NR45lXXEiR7AEtYCd1ETzq9Z61FTMQLb5O4-1hSf8sCrjdPB84e__xsrItKHL3qjJALgbYN-H_VQ==">>}
|
||||
]},
|
||||
|
||||
{pools, [
|
||||
%% redis连接池
|
||||
{redis_pool,
|
||||
[{size, 10}, {max_overflow, 20}, {worker_module, eredis}],
|
||||
@ -66,16 +57,6 @@
|
||||
{port, 6379},
|
||||
{database, 1}
|
||||
]
|
||||
},
|
||||
|
||||
%% influxdb数据库配置
|
||||
{influx_pool,
|
||||
[{size, 100}, {max_overflow, 200}, {worker_module, influx_client}],
|
||||
[
|
||||
{host, "172.19.0.4"},
|
||||
{port, 8086},
|
||||
{token, <<"A-ZRjqMK_7NR45lXXEiR7AEtYCd1ETzq9Z61FTMQLb5O4-1hSf8sCrjdPB84e__xsrItKHL3qjJALgbYN-H_VQ==">>}
|
||||
]
|
||||
}
|
||||
|
||||
]}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user