Skip to content
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

Reduce ETSCronFlusher memory consumption #199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/prom_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ defmodule PromEx do
else: :prom_ex_down
end

@doc """
Forces aggregation for all currently configured distributions (histogram). This is
primarily used by flusher process to prevent high memory consumptions.
"""
@spec aggregate_metrics(prom_ex_module :: module()) :: :ok | :prom_ex_down
def aggregate_metrics(prom_ex_module) do
prom_ex_process_name = prom_ex_module.__metrics_collector_name__()

if Process.whereis(prom_ex_process_name),
do: Core.aggregate(prom_ex_process_name),
else: :prom_ex_down
end

@callback init_opts :: PromEx.Config.t()
@callback plugins :: [plugin_definition()]
@callback dashboard_assigns :: keyword()
Expand Down
4 changes: 2 additions & 2 deletions lib/prom_ex/ets_cron_flusher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ defmodule PromEx.ETSCronFlusher do

@impl true
def handle_info(:flush_ets, state) do
PromEx.get_metrics(state.prom_ex_module)
PromEx.aggregate_metrics(state.prom_ex_module)

timer_ref = schedule_flush(state)
{:noreply, %{state | timer_ref: timer_ref}}
{:noreply, %{state | timer_ref: timer_ref}, :hibernate}
end

@impl true
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule PromEx.MixProject do
{:telemetry, ">= 1.0.0"},
{:telemetry_poller, "~> 1.0"},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_metrics_prometheus_core, "~> 1.0"},
{:telemetry_metrics_prometheus_core, github: "IIILSW/telemetry_metrics_prometheus_core"},
{:plug_cowboy, "~> 2.5 or ~> 2.6"},
{:octo_fetch, "~> 0.3"},

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
"telemetry_metrics_prometheus_core": {:hex, :telemetry_metrics_prometheus_core, "1.0.2", "c98b1c580de637bfeac00db41b9fb91fb4c3548ee3d512a8ed7299172312eaf3", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "48351a0d56f80e38c997b44232b1043e0a081670d16766eee920e6254175b730"},
"telemetry_metrics_prometheus_core": {:git, "https://github.com/IIILSW/telemetry_metrics_prometheus_core.git", "a90f72a65fec1e21840fda4c0fc41d589525e114", []},
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}