Merge pull request #11208 from HJianBo/update-lwm2m-stats
fix(lwm2m): update the stats correctly and timely
This commit is contained in:
commit
2f33fd9bac
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_gateway_lwm2m, [
|
{application, emqx_gateway_lwm2m, [
|
||||||
{description, "LwM2M Gateway"},
|
{description, "LwM2M Gateway"},
|
||||||
{vsn, "0.1.1"},
|
{vsn, "0.1.2"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [kernel, stdlib, emqx, emqx_gateway, emqx_gateway_coap]},
|
{applications, [kernel, stdlib, emqx, emqx_gateway, emqx_gateway_coap]},
|
||||||
{env, []},
|
{env, []},
|
||||||
|
|
|
@ -111,8 +111,8 @@ info(clientid, #channel{clientinfo = #{clientid := ClientId}}) ->
|
||||||
info(ctx, #channel{ctx = Ctx}) ->
|
info(ctx, #channel{ctx = Ctx}) ->
|
||||||
Ctx.
|
Ctx.
|
||||||
|
|
||||||
stats(_) ->
|
stats(#channel{session = Session}) ->
|
||||||
[].
|
emqx_lwm2m_session:stats(Session).
|
||||||
|
|
||||||
init(
|
init(
|
||||||
ConnInfo = #{
|
ConnInfo = #{
|
||||||
|
@ -246,7 +246,7 @@ handle_call(
|
||||||
Subs = emqx_lwm2m_session:info(subscriptions, Session),
|
Subs = emqx_lwm2m_session:info(subscriptions, Session),
|
||||||
NSubs = maps:put(MountedTopic, NSubOpts, Subs),
|
NSubs = maps:put(MountedTopic, NSubOpts, Subs),
|
||||||
NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session),
|
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(
|
handle_call(
|
||||||
{unsubscribe, Topic},
|
{unsubscribe, Topic},
|
||||||
_From,
|
_From,
|
||||||
|
@ -269,7 +269,7 @@ handle_call(
|
||||||
Subs = emqx_lwm2m_session:info(subscriptions, Session),
|
Subs = emqx_lwm2m_session:info(subscriptions, Session),
|
||||||
NSubs = maps:remove(MountedTopic, Subs),
|
NSubs = maps:remove(MountedTopic, Subs),
|
||||||
NSession = emqx_lwm2m_session:set_subscriptions(NSubs, Session),
|
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}) ->
|
handle_call(subscriptions, _From, Channel = #channel{session = Session}) ->
|
||||||
Subs = maps:to_list(emqx_lwm2m_session:info(subscriptions, Session)),
|
Subs = maps:to_list(emqx_lwm2m_session:info(subscriptions, Session)),
|
||||||
{reply, {ok, Subs}, Channel};
|
{reply, {ok, Subs}, Channel};
|
||||||
|
|
|
@ -248,11 +248,11 @@ stats(subscriptions_max, _) ->
|
||||||
stats(inflight_cnt, _) ->
|
stats(inflight_cnt, _) ->
|
||||||
0;
|
0;
|
||||||
stats(inflight_max, _) ->
|
stats(inflight_max, _) ->
|
||||||
0;
|
infinity;
|
||||||
stats(mqueue_len, _) ->
|
stats(mqueue_len, _) ->
|
||||||
0;
|
0;
|
||||||
stats(mqueue_max, _) ->
|
stats(mqueue_max, _) ->
|
||||||
0;
|
infinity;
|
||||||
stats(mqueue_dropped, _) ->
|
stats(mqueue_dropped, _) ->
|
||||||
0;
|
0;
|
||||||
stats(next_pkt_id, _) ->
|
stats(next_pkt_id, _) ->
|
||||||
|
|
|
@ -2486,6 +2486,12 @@ case100_subscription_api(Config) ->
|
||||||
},
|
},
|
||||||
{201, _} = request(post, Path, SubReq),
|
{201, _} = request(post, Path, SubReq),
|
||||||
{200, _} = request(get, Path),
|
{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"),
|
{204, _} = request(delete, Path ++ "/tx"),
|
||||||
{200, [InitSub]} = request(get, Path).
|
{200, [InitSub]} = request(get, Path).
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix the issue of abnormal data statistics for LwM2M client.
|
Loading…
Reference in New Issue