feat: add overload_protection metrics to prometheus

This commit is contained in:
zhongwencool 2023-08-23 14:07:37 +08:00
parent 61536b5362
commit df9f8da178
2 changed files with 39 additions and 1 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_prometheus, [
{description, "Prometheus for EMQX"},
% strict semver, bump manually!
{vsn, "5.0.15"},
{vsn, "5.0.16"},
{modules, []},
{registered, [emqx_prometheus_sup]},
{applications, [kernel, stdlib, prometheus, emqx, emqx_management]},

View File

@ -168,6 +168,7 @@ collect_mf(_Registry, Callback) ->
_ = [add_collect_family(Name, Metrics, Callback, counter) || Name <- emqx_metrics_delivery()],
_ = [add_collect_family(Name, Metrics, Callback, counter) || Name <- emqx_metrics_client()],
_ = [add_collect_family(Name, Metrics, Callback, counter) || Name <- emqx_metrics_session()],
_ = [add_collect_family(Name, Metrics, Callback, counter) || Name <- emqx_metrics_olp()],
ok.
%% @private
@ -437,6 +438,19 @@ emqx_collect(emqx_session_discarded, Stats) ->
emqx_collect(emqx_session_terminated, Stats) ->
counter_metric(?C('session.terminated', Stats));
%%--------------------------------------------------------------------
%% Metrics - overload protection
emqx_collect(emqx_overload_protection_delay_ok, Stats) ->
counter_metric(?C('olp.delay.ok', Stats));
emqx_collect(emqx_overload_protection_delay_timeout, Stats) ->
counter_metric(?C('olp.delay.timeout', Stats));
emqx_collect(emqx_overload_protection_hibernation, Stats) ->
counter_metric(?C('olp.hbn', Stats));
emqx_collect(emqx_overload_protection_gc, Stats) ->
counter_metric(?C('olp.gc', Stats));
emqx_collect(emqx_overload_protection_new_conn, Stats) ->
counter_metric(?C('olp.new_conn', Stats));
%%--------------------------------------------------------------------
%% VM
emqx_collect(emqx_vm_cpu_use, VMData) ->
@ -506,6 +520,30 @@ emqx_metrics_packets() ->
emqx_packets_auth_sent
].
emqx_metrics_olp() ->
case is_olp_enabled() of
true ->
[
emqx_overload_protection_delay_ok,
emqx_overload_protection_delay_timeout,
emqx_overload_protection_hibernation,
emqx_overload_protection_gc,
emqx_overload_protection_new_conn
];
false ->
[]
end.
is_olp_enabled() ->
maps:fold(
fun
(_, #{overload_protection := #{enable := true}}, _Acc) -> true;
(_, _, Acc) -> Acc
end,
false,
emqx_conf:get([zones], #{})
).
emqx_metrics_messages() ->
[
emqx_messages_received,