Skip to content

Commit

Permalink
Merge pull request #9473 from rabbitmq/mergify/bp/v3.12.x/pr-9465
Browse files Browse the repository at this point in the history
Expose number of unreachable cluster peers via Prometheus (backport #9465)
  • Loading branch information
michaelklishin authored Sep 19, 2023
2 parents c3d680f + 2b29976 commit d13727e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions deps/rabbitmq_prometheus/app.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def all_beam_files(name = "all_beam_files"):
"src/collectors/prometheus_process_collector.erl",
"src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_core_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_dynamic_collector.erl",
"src/collectors/prometheus_rabbitmq_global_metrics_collector.erl",
"src/rabbit_prometheus_app.erl",
"src/rabbit_prometheus_dispatcher.erl",
Expand Down Expand Up @@ -42,6 +43,7 @@ def all_test_beam_files(name = "all_test_beam_files"):
"src/collectors/prometheus_process_collector.erl",
"src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_core_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_dynamic_collector.erl",
"src/collectors/prometheus_rabbitmq_global_metrics_collector.erl",
"src/rabbit_prometheus_app.erl",
"src/rabbit_prometheus_dispatcher.erl",
Expand Down Expand Up @@ -83,6 +85,7 @@ def all_srcs(name = "all_srcs"):
"src/collectors/prometheus_process_collector.erl",
"src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_core_metrics_collector.erl",
"src/collectors/prometheus_rabbitmq_dynamic_collector.erl",
"src/collectors/prometheus_rabbitmq_global_metrics_collector.erl",
"src/rabbit_prometheus_app.erl",
"src/rabbit_prometheus_dispatcher.erl",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
%%% Collector for dynamic metrics that are calculated at collection time
-module(prometheus_rabbitmq_dynamic_collector).

-behaviour(prometheus_collector).
-include_lib("prometheus/include/prometheus.hrl").

-export([deregister_cleanup/1,
collect_mf/2]).

-define(METRIC_NAME_PREFIX, "rabbitmq_").

-define(METRICS, [{unreachable_cluster_peers_count, gauge,
"Number of peers in the cluster the current node cannot reach."}
]).

%%====================================================================
%% Collector API
%%====================================================================

deregister_cleanup(_) -> ok.

collect_mf(_Registry, Callback) ->
_ = lists:foreach(
fun({Name, Type, Help}) ->
Callback(
prometheus_model_helpers:create_mf(
?METRIC_NAME(Name),
Help,
Type,
values(Name))
)
end,
?METRICS
),
ok.

%%====================================================================
%% Private Parts
%%====================================================================

values(unreachable_cluster_peers_count) ->
[{[], length(rabbit_nodes:list_unreachable())}].
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ build_dispatcher() ->
prometheus_rabbitmq_core_metrics_collector,
prometheus_rabbitmq_global_metrics_collector,
prometheus_rabbitmq_alarm_metrics_collector,
prometheus_rabbitmq_dynamic_collector,
prometheus_process_collector]),
prometheus_registry:register_collectors('per-object', [
prometheus_vm_system_info_collector,
Expand Down

0 comments on commit d13727e

Please sign in to comment.