Merge pull request #11208 from HJianBo/update-lwm2m-stats

fix(lwm2m): update the stats correctly and timely
This commit is contained in:
JianBo He 2023-07-07 15:32:50 +08:00 committed by GitHub
commit 2f33fd9bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_gateway_lwm2m, [
{description, "LwM2M Gateway"},
{vsn, "0.1.1"},
{vsn, "0.1.2"},
{registered, []},
{applications, [kernel, stdlib, emqx, emqx_gateway, emqx_gateway_coap]},
{env, []},

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).

View File

@ -0,0 +1 @@
Fix the issue of abnormal data statistics for LwM2M client.