Просмотр исходного кода

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

fix(lwm2m): update the stats correctly and timely
JianBo He 2 лет назад
Родитель
Сommit
2f33fd9bac

+ 1 - 1
apps/emqx_gateway_lwm2m/src/emqx_gateway_lwm2m.app.src

@@ -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, []},

+ 4 - 4
apps/emqx_gateway_lwm2m/src/emqx_lwm2m_channel.erl

@@ -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};

+ 2 - 2
apps/emqx_gateway_lwm2m/src/emqx_lwm2m_session.erl

@@ -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, _) ->

+ 6 - 0
apps/emqx_gateway_lwm2m/test/emqx_lwm2m_SUITE.erl

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

+ 1 - 0
changes/ce/fix-11208.en.md

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