Skip to content

Commit

Permalink
use_mgmt_auth option, bump verion
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Sep 16, 2018
1 parent cb79014 commit 9351ff6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/prometheus_rabbitmq_exporter.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, prometheus_rabbitmq_exporter,
[{description, "RabbitMQ Prometheus.io metrics exporter"},
{vsn, "v3.7.2.2"},
{vsn, "v3.7.2.3"},
{modules, []},
{registered, []},
{env, []},
Expand Down
2 changes: 1 addition & 1 deletion src/prometheus_rabbitmq_exporter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dispatcher() ->

prometheus_http_impl:setup(),

[{Path ++ "/[:registry]", prometheus_cowboy2_handler, []}].
[{Path ++ "/[:registry]", prometheus_rabbitmq_exporter_handler, []}].

web_ui() -> [].

Expand Down
6 changes: 6 additions & 0 deletions src/prometheus_rabbitmq_exporter_config.erl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
-module(prometheus_rabbitmq_exporter_config).

-export([path/0,
use_mgmt_auth/0,
queue_messages_stat/0,
exchange_messages_stat/0,
memory_stat_enabled/0,
connections_total_enabled/0]).

-define(DEFAULT_PATH, "/metrics").
-define(DEFAULT_USE_MGMT_AUTH, false).
-define(DEFAULT_QUEUE_MESSAGES_STAT, [messages_published_total,
messages_confirmed_total,
messages_delivered_total,
Expand Down Expand Up @@ -37,6 +39,10 @@ path() ->
Config = config(),
proplists:get_value(path, Config, ?DEFAULT_PATH).

use_mgmt_auth() ->
Config = config(),
proplists:get_value(use_mgmt_auth, Config, ?DEFAULT_USE_MGMT_AUTH).

queue_messages_stat() ->
Config = config(),
proplists:get_value(queue_messages_stat, Config, ?DEFAULT_QUEUE_MESSAGES_STAT).
Expand Down
33 changes: 33 additions & 0 deletions src/prometheus_rabbitmq_exporter_handler.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-module(prometheus_rabbitmq_exporter_handler).

-export([init/2]).
-export([generate_response/2, content_types_provided/2, is_authorized/2]).

-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").

%% ===================================================================
%% Cowboy Handler Callbacks
%% ===================================================================

init(Req, _State) ->
{cowboy_rest, Req, #context{}}.

content_types_provided(ReqData, Context) ->
{[
{<<"*/*">>, generate_response}
], ReqData, Context}.

is_authorized(ReqData, Context) ->
case prometheus_rabbitmq_exporter_config:use_mgmt_auth() of
false ->
{true, ReqData, Context};
true ->
rabbit_mgmt_util:is_authorized(ReqData, Context)
end.

%% ===================================================================
%% Private functions
%% ===================================================================

generate_response(ReqData, Context) ->
prometheus_cowboy2_handler:init(ReqData, Context).

0 comments on commit 9351ff6

Please sign in to comment.