From f8f6c78c7c9e1de763d3af815e0dbdba9bb2c2a7 Mon Sep 17 00:00:00 2001 From: Qwerty5Uiop <105209995+Qwerty5Uiop@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:55:20 +0400 Subject: [PATCH] feat: Add memory metrics for OnDemand fetchers (#10425) --- apps/indexer/lib/indexer/memory/monitor.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/indexer/lib/indexer/memory/monitor.ex b/apps/indexer/lib/indexer/memory/monitor.ex index 6fefce04a1..b48bb0b73c 100644 --- a/apps/indexer/lib/indexer/memory/monitor.ex +++ b/apps/indexer/lib/indexer/memory/monitor.ex @@ -208,7 +208,7 @@ defmodule Indexer.Memory.Monitor do @megabytes_divisor 2 ** 20 defp set_metrics(%__MODULE__{shrinkable_set: shrinkable_set}) do total_memory = - Enum.reduce(shrinkable_set, 0, fn pid, acc -> + Enum.reduce(shrinkable_set ++ on_demand_fetchers(), 0, fn pid, acc -> memory = memory(pid) / @megabytes_divisor name = name(pid) @@ -220,6 +220,15 @@ defmodule Indexer.Memory.Monitor do Instrumenter.set_memory_consumed(:total, total_memory) end + defp on_demand_fetchers do + Enum.flat_map([Indexer.Application, Indexer.Supervisor, Explorer.Supervisor], fn supervisor -> + supervisor + |> Supervisor.which_children() + |> Enum.filter(fn {name, _, _, _} -> is_atom(name) and String.contains?(to_string(name), "OnDemand") end) + |> Enum.map(fn {_, pid, _, _} -> pid end) + end) + end + defp name(pid) do case Process.info(pid, :registered_name) do {:registered_name, name} when is_atom(name) ->