feat(olp): metrics
This commit is contained in:
parent
67267acb70
commit
4dc63b26a8
|
@ -325,6 +325,7 @@ recvloop(Parent, State = #state{idle_timeout = IdleTimeout}) ->
|
||||||
IdleTimeout + 100 ->
|
IdleTimeout + 100 ->
|
||||||
case emqx_olp:is_overloaded() of
|
case emqx_olp:is_overloaded() of
|
||||||
true ->
|
true ->
|
||||||
|
emqx_metrics:inc('olp.hbn'),
|
||||||
recvloop(Parent, State);
|
recvloop(Parent, State);
|
||||||
false ->
|
false ->
|
||||||
hibernate(Parent, cancel_stats_timer(State))
|
hibernate(Parent, cancel_stats_timer(State))
|
||||||
|
|
|
@ -184,6 +184,15 @@
|
||||||
{counter, 'session.terminated'}
|
{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(state, {next_idx = 1}).
|
||||||
|
|
||||||
-record(metric, {name, type, idx}).
|
-record(metric, {name, type, idx}).
|
||||||
|
@ -430,7 +439,8 @@ init([]) ->
|
||||||
?MESSAGE_METRICS,
|
?MESSAGE_METRICS,
|
||||||
?DELIVERY_METRICS,
|
?DELIVERY_METRICS,
|
||||||
?CLIENT_METRICS,
|
?CLIENT_METRICS,
|
||||||
?SESSION_METRICS
|
?SESSION_METRICS,
|
||||||
|
?OLP_METRICS
|
||||||
]),
|
]),
|
||||||
% Store reserved indices
|
% Store reserved indices
|
||||||
ok = lists:foreach(fun({Type, Name}) ->
|
ok = lists:foreach(fun({Type, Name}) ->
|
||||||
|
@ -571,5 +581,11 @@ reserved_idx('session.takeovered') -> 222;
|
||||||
reserved_idx('session.discarded') -> 223;
|
reserved_idx('session.discarded') -> 223;
|
||||||
reserved_idx('session.terminated') -> 224;
|
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.
|
reserved_idx(_) -> undefined.
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,20 @@
|
||||||
is_overloaded() ->
|
is_overloaded() ->
|
||||||
load_ctl:is_overloaded().
|
load_ctl:is_overloaded().
|
||||||
|
|
||||||
-spec backoff(Zone :: atom()) -> ok | timeout.
|
-spec backoff(Zone :: atom()) -> ok | false | timeout.
|
||||||
backoff(Zone) ->
|
backoff(Zone) ->
|
||||||
case emqx_config:get_zone_conf(Zone, [overload_protection, enable], false) of
|
case emqx_config:get_zone_conf(Zone, [overload_protection, enable], false) of
|
||||||
true ->
|
true ->
|
||||||
Delay = emqx_config:get_zone_conf(Zone, [overload_protection, backoff_delay], 1),
|
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 ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -46,6 +46,7 @@ new_conn(Conn, S) ->
|
||||||
{error, stream_accept_error}
|
{error, stream_accept_error}
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
|
emqx_metrics:inc('olp.close.quic'),
|
||||||
{error, overloaded}
|
{error, overloaded}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue