-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expose alarms as Prometheus metrics #3312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
deps/rabbitmq_prometheus/src/collectors/prometheus_rabbitmq_alarm_metrics_collector.erl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
%% This Source Code Form is subject to the terms of the Mozilla Public | ||
%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%% | ||
%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved. | ||
%% | ||
-module(prometheus_rabbitmq_alarm_metrics_collector). | ||
|
||
-export([register/0, deregister_cleanup/1, collect_mf/2]). | ||
|
||
-import(prometheus_model_helpers, [create_mf/4, untyped_metric/1]). | ||
|
||
-include_lib("prometheus/include/prometheus.hrl"). | ||
|
||
-behaviour(prometheus_collector). | ||
|
||
-define(METRIC_NAME_PREFIX, "rabbitmq_alarms_"). | ||
|
||
%%==================================================================== | ||
%% Collector API | ||
%%==================================================================== | ||
|
||
register() -> | ||
ok = prometheus_registry:register_collector(?MODULE). | ||
|
||
deregister_cleanup(_) -> | ||
ok. | ||
|
||
-spec collect_mf(_Registry, Callback) -> ok | ||
when _Registry :: prometheus_registry:registry(), | ||
Callback :: prometheus_collector:callback(). | ||
collect_mf(_Registry, Callback) -> | ||
try | ||
case rabbit_alarm:get_local_alarms(500) %% TODO: figure out timeout | ||
of | ||
Alarms when is_list(Alarms) -> | ||
ActiveAlarms = | ||
lists:foldl(fun ({{resource_limit, disk, _}, _}, Acc) -> | ||
maps:put(disk_limit, 1, Acc); | ||
({{resource_limit, memory, _}, _}, Acc) -> | ||
maps:put(memory_limit, 1, Acc); | ||
({file_descriptor_limit, _}, Acc) -> | ||
maps:put(file_descriptor_limit, 1, Acc) | ||
end, | ||
#{}, | ||
Alarms), | ||
|
||
Callback(create_mf(?METRIC_NAME(<<"file_descriptor_limit">>), | ||
<<"is 1 if file descriptor limit alarm is in effect">>, | ||
untyped, | ||
[untyped_metric(maps:get(file_descriptor_limit, | ||
ActiveAlarms, | ||
0))])), | ||
Callback(create_mf(?METRIC_NAME(<<"free_disk_space_watermark">>), | ||
<<"is 1 if free disk space watermark alarm is in effect">>, | ||
untyped, | ||
[untyped_metric(maps:get(disk_limit, ActiveAlarms, 0))])), | ||
Callback(create_mf(?METRIC_NAME(<<"memory_used_watermark">>), | ||
<<"is 1 if VM memory watermark alarm is in effect">>, | ||
untyped, | ||
[untyped_metric(maps:get(memory_limit, ActiveAlarms, 0))])), | ||
ok; | ||
Error -> | ||
rabbit_log:error("alarm_metrics_collector failed to emit metrics: " | ||
"rabbitm_alarm:get_local_alarms returned ~p", | ||
[Error]), | ||
%% We are not going to render any alarm metrics here. | ||
%% Breaks continuity but at least doesn't crash the | ||
%% whole scraping endpoint | ||
ok | ||
end | ||
catch | ||
exit:{timeout, _} -> | ||
rabbit_log:error("alarm_metrics_collector failed to emit metrics: " | ||
"rabbitm_alarm:get_local_alarms timed out"), | ||
%% We are not going to render any alarm metrics here. | ||
%% Breaks continuity but at least doesn't crash the | ||
%% whole scraping endpoint | ||
ok | ||
end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.