feat(olp): metrics

This commit is contained in:
William Yang 2021-10-04 15:03:14 +02:00
parent 67267acb70
commit 4dc63b26a8
4 changed files with 29 additions and 3 deletions

View File

@ -325,6 +325,7 @@ recvloop(Parent, State = #state{idle_timeout = IdleTimeout}) ->
IdleTimeout + 100 ->
case emqx_olp:is_overloaded() of
true ->
emqx_metrics:inc('olp.hbn'),
recvloop(Parent, State);
false ->
hibernate(Parent, cancel_stats_timer(State))

View File

@ -184,6 +184,15 @@
{counter, 'session.terminated'}
]).
%% Overload protetion counters
-define(OLP_METRICS,
[{counter, 'olp.delay.ok'},
{counter, 'olp.delay.timeout'},
{counter, 'olp.hbn'},
{counter, 'olp.gc'},
{counter, 'olp.close.quic'}
]).
-record(state, {next_idx = 1}).
-record(metric, {name, type, idx}).
@ -430,7 +439,8 @@ init([]) ->
?MESSAGE_METRICS,
?DELIVERY_METRICS,
?CLIENT_METRICS,
?SESSION_METRICS
?SESSION_METRICS,
?OLP_METRICS
]),
% Store reserved indices
ok = lists:foreach(fun({Type, Name}) ->
@ -571,5 +581,11 @@ reserved_idx('session.takeovered') -> 222;
reserved_idx('session.discarded') -> 223;
reserved_idx('session.terminated') -> 224;
reserved_idx('olp.delay.ok') -> 300;
reserved_idx('olp.delay.timeout') -> 301;
reserved_idx('olp.hbn') -> 302;
reserved_idx('olp.gc') -> 303;
reserved_idx('olp.close.quic') -> 304;
reserved_idx(_) -> undefined.

View File

@ -32,12 +32,20 @@
is_overloaded() ->
load_ctl:is_overloaded().
-spec backoff(Zone :: atom()) -> ok | timeout.
-spec backoff(Zone :: atom()) -> ok | false | timeout.
backoff(Zone) ->
case emqx_config:get_zone_conf(Zone, [overload_protection, enable], false) of
true ->
Delay = emqx_config:get_zone_conf(Zone, [overload_protection, backoff_delay], 1),
load_ctl:maydelay(Delay);
case load_ctl:maydelay(Delay) of
false -> false;
ok ->
emqx_metrics:inc('olp.delay.ok'),
ok;
timeout ->
emqx_metrics:inc('olp.delay.timeout'),
timeout
end;
false ->
ok
end.

View File

@ -46,6 +46,7 @@ new_conn(Conn, S) ->
{error, stream_accept_error}
end;
true ->
emqx_metrics:inc('olp.close.quic'),
{error, overloaded}
end.