Skip to content

Commit

Permalink
using a db query to populate host active state metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dgulinobw committed Aug 29, 2024
1 parent 793bb99 commit da7b6bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/dog_host.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
-export([
create/1,
delete/1,
get_all/0,
get_all_active/0,
get_by_hostkey/1,
get_by_id/1,
get_by_name/1,
get_all/0,
get_all_active/0,
get_id_by_hostkey/1,
get_schema/0,
update/2,
update_by_hostkey/2,
get_id_by_hostkey/1
update_by_hostkey/2
]).

-export([
get_all_active_interfaces/0,
get_all_joined_with_group/0,
get_grouped_active_states/0,
get_hostkeys_by_ips/0,
get_names_by_ips/0,
hash_check/1,
Expand All @@ -30,8 +32,7 @@
keepalive_age_check/0, keepalive_age_check/1,
keepalive_check/0, keepalive_check/1,
retirement_check/0, retirement_check/1,
state_event/3,
get_all_joined_with_group/0
state_event/3
]).

-spec get_all_joined_with_group() -> HostsGroups :: map().
Expand Down Expand Up @@ -685,6 +686,18 @@ get_all_active() ->
end,
{ok, Hosts}.

-spec get_grouped_active_states() -> {ok, {grouped, list() }}.
get_grouped_active_states() ->
{ok, Result} = dog_rethink:run(
fun(X) ->
reql:db(X, dog),
reql:table(X, ?TYPE_TABLE),
reql:group(X, <<"active">>),
reql:count(X)
end
),
{ok, Result}.

get_names_by_ips() ->
get_by_ips(<<"name">>).

Expand Down
8 changes: 8 additions & 0 deletions src/dog_keepalive_agent.erl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,18 @@ code_change(_OldVsn, State, _Extra) ->
%% Internal Function Definitions
%% ------------------------------------------------------------------

-spec do_host_active_state_metrics() -> null.
do_host_active_state_metrics() ->
{ok, {grouped, States}} = dog_host:get_grouped_active_states(),
lists:foreach(fun([State,Count]) ->
imetrics:set_gauge_m(<<"host_active_state">>, State, Count)
end,
States).
%% @doc Makes a call to the nif to add a resource to
%% watch. Logs on error
-spec do_watch_keepalives(_) -> ok | pass.
do_watch_keepalives(_State) ->
do_host_active_state_metrics(),
case dog_agent_checker:check() of
true ->
{ok, HostsRetirementCheck} = dog_host:retirement_check(),
Expand Down

0 comments on commit da7b6bd

Please sign in to comment.