diff --git a/deps/rabbitmq_prometheus/app.bzl b/deps/rabbitmq_prometheus/app.bzl index 2370b1afa9db..491f772c520a 100644 --- a/deps/rabbitmq_prometheus/app.bzl +++ b/deps/rabbitmq_prometheus/app.bzl @@ -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", @@ -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", @@ -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", diff --git a/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_dynamic_collector.erl b/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_dynamic_collector.erl new file mode 100644 index 000000000000..32f60937f965 --- /dev/null +++ b/deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_dynamic_collector.erl @@ -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())}]. diff --git a/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl b/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl index 8125ddcc4b2e..963060dc13e4 100644 --- a/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl +++ b/deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl @@ -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,