fix(lwm2m): update the stats correctly and timely

This commit is contained in:
JianBo He 2023-07-06 16:12:45 +08:00
parent ab809c8b85
commit 31a240ba63
3 changed files with 12 additions and 6 deletions

View File

@ -111,8 +111,8 @@ info(clientid, #channel{clientinfo = #{clientid := ClientId}}) ->
info(ctx, #channel{ctx = Ctx}) ->
Ctx.
stats(_) ->
[].
stats(#channel{session = Session}) ->
emqx_lwm2m_session:stats(Session).
init(
ConnInfo = #{
@ -246,7 +246,7 @@ handle_call(
Subs = emqx_lwm2m_session:info(subscriptions, Session),
NSubs = maps:put(MountedTopic, NSubOpts, Subs),
NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session),
{reply, {ok, {MountedTopic, NSubOpts}}, Channel#channel{session = NSession}};
{reply, {ok, {MountedTopic, NSubOpts}}, [{event, updated}], Channel#channel{session = NSession}};
handle_call(
{unsubscribe, Topic},
_From,
@ -269,7 +269,7 @@ handle_call(
Subs = emqx_lwm2m_session:info(subscriptions, Session),
NSubs = maps:remove(MountedTopic, Subs),
NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session),
{reply, ok, Channel#channel{session = NSession}};
{reply, ok, [{event, updated}], Channel#channel{session = NSession}};
handle_call(subscriptions, _From, Channel = #channel{session = Session}) ->
Subs = maps:to_list(emqx_lwm2m_session:info(subscriptions, Session)),
{reply, {ok, Subs}, Channel};

View File

@ -248,11 +248,11 @@ stats(subscriptions_max, _) ->
stats(inflight_cnt, _) ->
0;
stats(inflight_max, _) ->
0;
infinity;
stats(mqueue_len, _) ->
0;
stats(mqueue_max, _) ->
0;
infinity;
stats(mqueue_dropped, _) ->
0;
stats(next_pkt_id, _) ->

View File

@ -2486,6 +2486,12 @@ case100_subscription_api(Config) ->
},
{201, _} = request(post, Path, SubReq),
{200, _} = request(get, Path),
%% check subscription_cnt
{200, #{subscriptions_cnt := 2}} = request(
get, "/gateways/lwm2m/clients/" ++ binary_to_list(ClientId)
),
{204, _} = request(delete, Path ++ "/tx"),
{200, [InitSub]} = request(get, Path).