Skip to content

Commit e8d5d83

Browse files
committed
Return Ra counters from /metrics/per-object
1 parent d8ff40f commit e8d5d83

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
-module(prometheus_rabbitmq_raft_metrics_collector).
8+
9+
-behaviour(prometheus_collector).
10+
-include_lib("prometheus/include/prometheus.hrl").
11+
12+
-export([register/0,
13+
deregister_cleanup/1,
14+
collect_mf/2]).
15+
16+
-import(prometheus_model_helpers, [create_mf/4,
17+
counter_metric/2]).
18+
19+
-define(METRIC_NAME_PREFIX, "rabbitmq_raft_").
20+
21+
%%====================================================================
22+
%% Collector API
23+
%%====================================================================
24+
25+
register() ->
26+
ok = prometheus_registry:register_collector(?MODULE).
27+
28+
deregister_cleanup(_) ->
29+
ok.
30+
31+
collect_mf(_Registry, Callback) ->
32+
maps:foreach(
33+
fun(Name, #{type := Type, help := Help, values := Values}) ->
34+
Callback(
35+
create_mf(?METRIC_NAME(Name),
36+
Help,
37+
Type,
38+
maps:to_list(Values)))
39+
end,
40+
seshat:format(ra, [term,
41+
snapshot_index,
42+
last_applied,
43+
commit_index,
44+
last_written_index,
45+
commit_latency,
46+
num_segments])).

deps/rabbitmq_prometheus/src/rabbit_prometheus_dispatcher.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ build_dispatcher() ->
2929
prometheus_vm_msacc_collector,
3030
prometheus_rabbitmq_core_metrics_collector,
3131
prometheus_rabbitmq_global_metrics_collector,
32+
prometheus_rabbitmq_raft_metrics_collector,
3233
prometheus_rabbitmq_message_size_metrics_collector
3334
]),
3435
prometheus_registry:register_collectors('detailed', [

0 commit comments

Comments
 (0)