fix zd stat
This commit is contained in:
parent
24b29bac21
commit
3eac69633e
@ -36,10 +36,7 @@
|
|||||||
%% 定时器
|
%% 定时器
|
||||||
timer_ref :: undefined | reference(),
|
timer_ref :: undefined | reference(),
|
||||||
%% 是否繁忙
|
%% 是否繁忙
|
||||||
is_busy = false :: boolean(),
|
is_busy = false :: boolean()
|
||||||
|
|
||||||
%% 记录成功处理的消息数, 记日期和总数的映射关系
|
|
||||||
acc_num = #{}
|
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
@ -136,7 +133,7 @@ handle_event(info, fetch_next, connected, State = #state{postman_pid = PostmanPi
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 收到确认消息
|
%% 收到确认消息
|
||||||
handle_event(info, {ack, AssocMessage}, StateName, State = #state{timer_ref = TimerRef, acc_num = AccNum, logger_pid = LoggerPid}) ->
|
handle_event(info, {ack, AssocMessage}, StateName, State = #state{timer_ref = TimerRef, logger_pid = LoggerPid}) ->
|
||||||
%% 记录日志信息
|
%% 记录日志信息
|
||||||
iot_logger:write(LoggerPid, AssocMessage),
|
iot_logger:write(LoggerPid, AssocMessage),
|
||||||
|
|
||||||
@ -146,11 +143,10 @@ handle_event(info, {ack, AssocMessage}, StateName, State = #state{timer_ref = Ti
|
|||||||
end,
|
end,
|
||||||
is_reference(TimerRef) andalso erlang:cancel_timer(TimerRef),
|
is_reference(TimerRef) andalso erlang:cancel_timer(TimerRef),
|
||||||
|
|
||||||
Date = iot_util:date(),
|
Key = get_counter_key(iot_util:date()),
|
||||||
Num = maps:get(Date, AccNum, 0),
|
mnesia_counter:inc(Key),
|
||||||
NAccNum = AccNum#{Date => Num + 1},
|
|
||||||
|
|
||||||
{keep_state, State#state{timer_ref = undefined, acc_num = NAccNum, is_busy = false}, Actions};
|
{keep_state, State#state{timer_ref = undefined, is_busy = false}, Actions};
|
||||||
|
|
||||||
%% 收到重发过期请求
|
%% 收到重发过期请求
|
||||||
handle_event(info, {timeout, _, {repost_ticker, Body}}, connected, State = #state{postman_pid = PostmanPid}) ->
|
handle_event(info, {timeout, _, {repost_ticker, Body}}, connected, State = #state{postman_pid = PostmanPid}) ->
|
||||||
@ -177,7 +173,10 @@ handle_event(info, {timeout, _, create_postman}, disconnected, State = #state{mq
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 获取当前统计信息
|
%% 获取当前统计信息
|
||||||
handle_event({call, From}, get_stat, StateName, State = #state{acc_num = AccNum, iot_queue = Q}) ->
|
handle_event({call, From}, get_stat, StateName, State = #state{iot_queue = Q}) ->
|
||||||
|
Key = get_counter_key(iot_util:date()),
|
||||||
|
AccNum = mnesia_counter:get_count(Key),
|
||||||
|
|
||||||
Stat = #{
|
Stat = #{
|
||||||
<<"acc_num">> => AccNum,
|
<<"acc_num">> => AccNum,
|
||||||
<<"queue_num">> => iot_queue:len(Q),
|
<<"queue_num">> => iot_queue:len(Q),
|
||||||
@ -186,8 +185,11 @@ handle_event({call, From}, get_stat, StateName, State = #state{acc_num = AccNum,
|
|||||||
{keep_state, State, [{reply, From, Stat}]};
|
{keep_state, State, [{reply, From, Stat}]};
|
||||||
|
|
||||||
%% 获取当前统计信息
|
%% 获取当前统计信息
|
||||||
handle_event({call, From}, {get_num, Date}, _StateName, State = #state{acc_num = AccNum}) ->
|
handle_event({call, From}, {get_num, Date}, _StateName, State = #state{}) ->
|
||||||
{keep_state, State, [{reply, From, maps:get(Date, AccNum, 0)}]};
|
Key = get_counter_key(Date),
|
||||||
|
AccNum = mnesia_counter:get_count(Key),
|
||||||
|
|
||||||
|
{keep_state, State, [{reply, From, AccNum}]};
|
||||||
|
|
||||||
%% postman进程挂掉时,重新建立新的
|
%% postman进程挂掉时,重新建立新的
|
||||||
handle_event(info, {'EXIT', PostmanPid, Reason}, connected, State = #state{timer_ref = TimerRef, postman_pid = PostmanPid}) ->
|
handle_event(info, {'EXIT', PostmanPid, Reason}, connected, State = #state{timer_ref = TimerRef, postman_pid = PostmanPid}) ->
|
||||||
@ -266,3 +268,7 @@ format_data(LocationCode, DynamicLocationCode, Fields, Timestamp) when is_binary
|
|||||||
lager:warning("[iot_zd_endpoint] location_code: ~p, format_data get error: ~p", [LocationCode, Reason]),
|
lager:warning("[iot_zd_endpoint] location_code: ~p, format_data get error: ~p", [LocationCode, Reason]),
|
||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_counter_key(Date :: string()) -> string().
|
||||||
|
get_counter_key(Date) when is_list(Date) ->
|
||||||
|
"iot_zd:" ++ Date.
|
||||||
Loading…
x
Reference in New Issue
Block a user