Add 'auth.mqtt.anonymous' metric (#2631)
* Add 'auth.mqtt.anonymous' metric
This commit is contained in:
parent
138d7727fa
commit
37eef7b72a
|
@ -29,7 +29,10 @@
|
||||||
-> {ok, emqx_types:credentials()} | {error, term()}).
|
-> {ok, emqx_types:credentials()} | {error, term()}).
|
||||||
authenticate(Credentials) ->
|
authenticate(Credentials) ->
|
||||||
case emqx_hooks:run_fold('client.authenticate', [], init_auth_result(Credentials)) of
|
case emqx_hooks:run_fold('client.authenticate', [], init_auth_result(Credentials)) of
|
||||||
#{auth_result := success} = NewCredentials ->
|
#{auth_result := success, anonymous := true} = NewCredentials ->
|
||||||
|
emqx_metrics:inc('auth.mqtt.anonymous'),
|
||||||
|
{ok, NewCredentials};
|
||||||
|
#{auth_result := success} = NewCredentials ->
|
||||||
{ok, NewCredentials};
|
{ok, NewCredentials};
|
||||||
NewCredentials ->
|
NewCredentials ->
|
||||||
{error, maps:get(auth_result, NewCredentials, unknown_error)}
|
{error, maps:get(auth_result, NewCredentials, unknown_error)}
|
||||||
|
|
|
@ -132,6 +132,10 @@
|
||||||
{counter, 'messages.forward'} % Messages forward
|
{counter, 'messages.forward'} % Messages forward
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-define(MQTT_METRICS, [
|
||||||
|
{counter, 'auth.mqtt.anonymous'}
|
||||||
|
]).
|
||||||
|
|
||||||
-record(state, {next_idx = 1}).
|
-record(state, {next_idx = 1}).
|
||||||
|
|
||||||
-record(metric, {name, type, idx}).
|
-record(metric, {name, type, idx}).
|
||||||
|
@ -355,7 +359,7 @@ init([]) ->
|
||||||
Metric = #metric{name = Name, type = Type, idx = reserved_idx(Name)},
|
Metric = #metric{name = Name, type = Type, idx = reserved_idx(Name)},
|
||||||
true = ets:insert(?TAB, Metric),
|
true = ets:insert(?TAB, Metric),
|
||||||
ok = counters:put(CRef, Idx, 0)
|
ok = counters:put(CRef, Idx, 0)
|
||||||
end,?BYTES_METRICS ++ ?PACKET_METRICS ++ ?MESSAGE_METRICS),
|
end,?BYTES_METRICS ++ ?PACKET_METRICS ++ ?MESSAGE_METRICS ++ ?MQTT_METRICS),
|
||||||
{ok, #state{next_idx = ?RESERVED_IDX + 1}, hibernate}.
|
{ok, #state{next_idx = ?RESERVED_IDX + 1}, hibernate}.
|
||||||
|
|
||||||
handle_call({create, Type, Name}, _From, State = #state{next_idx = ?MAX_SIZE}) ->
|
handle_call({create, Type, Name}, _From, State = #state{next_idx = ?MAX_SIZE}) ->
|
||||||
|
@ -446,4 +450,5 @@ reserved_idx('messages.retained') -> 48;
|
||||||
reserved_idx('messages.dropped') -> 49;
|
reserved_idx('messages.dropped') -> 49;
|
||||||
reserved_idx('messages.expired') -> 50;
|
reserved_idx('messages.expired') -> 50;
|
||||||
reserved_idx('messages.forward') -> 51;
|
reserved_idx('messages.forward') -> 51;
|
||||||
|
reserved_idx('auth.mqtt.anonymous') -> 52;
|
||||||
reserved_idx(_) -> undefined.
|
reserved_idx(_) -> undefined.
|
||||||
|
|
Loading…
Reference in New Issue