Skip to content

Commit

Permalink
Expose netsplit/partition info via Prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
gomoripeti committed Sep 12, 2023
1 parent d50e318 commit db5c0aa
Show file tree
Hide file tree
Showing 3 changed files with 53 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",
"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",
"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",
"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,49 @@
%%% 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]).

-import(prometheus_model_helpers, [create_mf/5,
gauge_metric/1,
gauge_metric/2]).

-define(METRIC_NAME_PREFIX, "rabbitmq_").

-define(METRICS, [{partitioned_from, gauge,
"Indicates that the current node is partitioned "
"from the peer node during a network partition."}
]).

%%====================================================================
%% 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(partitioned_from) ->
%% Note: partition info comes from Mnesia under the hood
[{[{peer, Node}], 1}
|| Node <- rabbit_node_monitor:partitions()].
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 db5c0aa

Please sign in to comment.