Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1e8afd0

Browse files
committed
add rabbitmq_connections_total, close #34
1 parent d2ca2a3 commit 1e8afd0

5 files changed

+55
-9
lines changed

Diff for: Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ ERLANG_MK_COMMIT = rabbitmq-tmp
2222
.PHONY: docker_build docker_push docker_latest docker_latest_pure
2323

2424
docker_build:
25-
docker build -t deadtrickster/rabbitmq_prometheus\:3.7.1 .
25+
docker build -t deadtrickster/rabbitmq_prometheus\:3.7.2 .
2626
docker build -t deadtrickster/rabbitmq_prometheus\:latest .
27-
docker build -t deadtrickster/rabbitmq_prometheus\:3.7.1-pure -f Dockerfile.pure .
27+
docker build -t deadtrickster/rabbitmq_prometheus\:3.7.2-pure -f Dockerfile.pure .
2828
docker build -t deadtrickster/rabbitmq_prometheus\:latest-pure -f Dockerfile.pure .
2929

3030
docker_push:
31-
docker push deadtrickster/rabbitmq_prometheus\:3.7.1
31+
docker push deadtrickster/rabbitmq_prometheus\:3.7.2
3232
docker push deadtrickster/rabbitmq_prometheus\:latest
33-
docker push deadtrickster/rabbitmq_prometheus\:3.7.1-pure
33+
docker push deadtrickster/rabbitmq_prometheus\:3.7.2-pure
3434
docker push deadtrickster/rabbitmq_prometheus\:latest-pure
3535

3636
docker_latest:

Diff for: README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ This exporter supports the following options via `rabbitmq_exporter` entry of `p
109109
- `path` - scrape endpoint. Default is `"metrics"`. Note RabbitMQ translates this to `"/api/metrics"`;
110110
- `format` - scrape format. Default is `prometheus_text_format`;
111111
- `exchange_messages_stat` - same as `queue_messages_state` but for the exchanges;
112-
- `queue_messages_stat` - messages state to export. Default is hopefully reasonable. You can read more about possible values [here](https://raw.githack.com/rabbitmq/rabbitmq-management/rabbitmq_v3_6_5/priv/www/doc/stats.html).
112+
- `queue_messages_stat` - messages state to export. Default is hopefully reasonable. You can read more about possible values [here](https://raw.githack.com/rabbitmq/rabbitmq-management/rabbitmq_v3_6_5/priv/www/doc/stats.html);
113+
- `connections_total_enabled` - Default is `false`. If `true`, the exporter will iterate over all connections and export count grouped by connection state (running, flow, etc).
113114

114-
Sample `/etc/rabbitmq/rabbitmq.config` showing how to customize the scrape `path`:
115+
Sample `/etc/rabbitmq/rabbitmq.config` showing how to customize the scrape `path`, and `connections_total_enabled`:
115116

116117
```erlang
117118
[
@@ -124,7 +125,8 @@ Sample `/etc/rabbitmq/rabbitmq.config` showing how to customize the scrape `path
124125
%% environment before the "rabbitmq_management" one.
125126
{prometheus, [
126127
{rabbitmq_exporter, [
127-
{path, "/mymetrics"}
128+
{path, "/mymetrics"},
129+
{connections_total_enabled, true}
128130
]}
129131
]},
130132
{rabbitmq_management, [
@@ -148,6 +150,11 @@ For the latest list of supported options look [here](https://github.com/deadtric
148150
Type: gauge.<br />
149151
RabbitMQ Connections count.
150152

153+
* `rabbitmq_connections_total` (disabled by default)<br />
154+
Type: gauge.<br />
155+
Labels: state.<br />
156+
RabbitMQ connections count grouped by connection state.
157+
151158
* `rabbitmq_channels`<br />
152159
Type: gauge.<br />
153160
RabbitMQ Channels count.

Diff for: src/collectors/prometheus_rabbitmq_overview_collector.erl

+32
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ collect_mf(_Registry, Callback) ->
118118
_ ->
119119
ok
120120
end,
121+
case prometheus_rabbitmq_exporter_config:connections_total_enabled() of
122+
true ->
123+
collect_rabbit_connections(Callback);
124+
_ ->
125+
ok
126+
end,
121127
ok.
122128

123129
collect_metrics(_, {messages_stat, MSKey, Stats}) ->
@@ -133,6 +139,32 @@ collect_rabbit_memory(Callback) ->
133139
Callback(create_mf(FullName, Help, gauge, Value))
134140
end || {Name, Help} <- ?MEMORY_METRICS].
135141

142+
collect_rabbit_connections(Callback) ->
143+
Table = ets:new('$$connectinos_stat$$', [set]),
144+
try
145+
Connections = ets:select(connection_stats, [{{'$1', '$2'}, [], ['$2']}], 10),
146+
connections_loop(Connections, Table),
147+
Callback(create_mf(?METRIC_NAME(connections_total), "RabbitMQ connections count grouped by connection state.",
148+
gauge, ets:tab2list(Table)))
149+
after
150+
ets:delete(Table)
151+
end,
152+
ok.
153+
154+
connections_loop('$end_of_table', _Table) ->
155+
ok;
156+
connections_loop({Connections, Continuation}, Table) ->
157+
[begin
158+
Labels = [{state, proplists:get_value(state, Connection)}],
159+
try
160+
ets:update_counter(Table, Labels, 1)
161+
catch error:badarg ->
162+
ets:insert(Table, {Labels, 1})
163+
end
164+
end
165+
|| Connection <- Connections],
166+
connections_loop(ets:select(Continuation), Table).
167+
136168
mf(Callback, Metric, Proplist) ->
137169
{Name, Type, Help, Fun} = case Metric of
138170
{Key, Type1, Help1} ->

Diff for: src/prometheus_rabbitmq_exporter.app.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, prometheus_rabbitmq_exporter,
22
[{description, "RabbitMQ Prometheus.io metrics exporter"},
3-
{vsn, "v3.7.1.1"},
3+
{vsn, "v3.7.2.1"},
44
{modules, []},
55
{registered, []},
66
{env, []},

Diff for: src/prometheus_rabbitmq_exporter_config.erl

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
-export([path/0,
44
queue_messages_stat/0,
55
exchange_messages_stat/0,
6-
memory_stat_enabled/0]).
6+
memory_stat_enabled/0,
7+
connections_total_enabled/0]).
78

89
-define(DEFAULT_PATH, "/metrics").
910
-define(DEFAULT_QUEUE_MESSAGES_STAT, [messages_published_total,
@@ -27,6 +28,7 @@
2728
messages_redelivered_total,
2829
messages_returned_total]).
2930
-define(DEFAULT_MEMORY_STAT_ENABLED, false).
31+
-define(DEFAULT_CONNECTIONS_TOTAL_ENABLED, false).
3032

3133
config() ->
3234
application:get_env(prometheus, rabbitmq_exporter, []).
@@ -46,3 +48,8 @@ exchange_messages_stat() ->
4648
memory_stat_enabled() ->
4749
Config = config(),
4850
proplists:get_value(memory_stat_enabled, Config, ?DEFAULT_MEMORY_STAT_ENABLED).
51+
52+
connections_total_enabled() ->
53+
Config = config(),
54+
proplists:get_value(connections_total_enabled, Config, ?DEFAULT_CONNECTIONS_TOTAL_ENABLED).
55+

0 commit comments

Comments
 (0)