chore: Enhance indexer memory metrics (#9984)

pull/9995/head
Qwerty5Uiop 7 months ago committed by GitHub
parent 1147280f8b
commit f2d7bd4df0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 32
      apps/indexer/lib/indexer/memory/monitor.ex
  2. 6
      apps/indexer/lib/indexer/prometheus/instrumenter.ex

@ -13,6 +13,7 @@ defmodule Indexer.Memory.Monitor do
import Indexer.Logger, only: [process: 1]
alias Indexer.Memory.Shrinkable
alias Indexer.Prometheus.Instrumenter
defstruct limit: 0,
timer_interval: :timer.minutes(1),
@ -68,6 +69,8 @@ defmodule Indexer.Memory.Monitor do
def handle_info(:check, state) do
total = :erlang.memory(:total)
set_metrics(state)
shrunk_state =
if memory_limit() < total do
log_memory(%{limit: memory_limit(), total: total})
@ -202,6 +205,35 @@ defmodule Indexer.Memory.Monitor do
end)
end
@megabytes_divisor 2 ** 20
defp set_metrics(%__MODULE__{shrinkable_set: shrinkable_set}) do
total_memory =
Enum.reduce(shrinkable_set, 0, fn pid, acc ->
memory = memory(pid) / @megabytes_divisor
name = name(pid)
Instrumenter.set_memory_consumed(name, memory)
acc + memory
end)
Instrumenter.set_memory_consumed(:total, total_memory)
end
defp name(pid) do
case Process.info(pid, :registered_name) do
{:registered_name, name} when is_atom(name) ->
name
|> to_string()
|> String.split(".")
|> Enum.slice(-2, 2)
|> Enum.join(".")
_ ->
nil
end
end
defp shrinkable_memory_pairs(%__MODULE__{shrinkable_set: shrinkable_set}) do
shrinkable_set
|> Enum.map(fn pid -> {pid, memory(pid)} end)

@ -35,6 +35,8 @@ defmodule Indexer.Prometheus.Instrumenter do
@counter [name: :import_errors_count, help: "Number of database import errors"]
@gauge [name: :memory_consumed, labels: [:fetcher], help: "Amount of memory consumed by fetchers (MB)"]
def block_full_process(time, fetcher) do
Histogram.observe([name: :block_full_processing_duration_microseconds, labels: [fetcher]], time)
end
@ -58,4 +60,8 @@ defmodule Indexer.Prometheus.Instrumenter do
def import_errors(error_count \\ 1) do
Counter.inc([name: :import_errors_count], error_count)
end
def set_memory_consumed(fetcher, memory) do
Gauge.set([name: :memory_consumed, labels: [fetcher]], memory)
end
end

Loading…
Cancel
Save