From 08c0ae9b4ca9102dd1e48a677f8b8959e008ff0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jan=20Niemier?= Date: Fri, 13 Dec 2024 18:17:00 +0100 Subject: [PATCH] fix: properly compute socket usage This partially reverts commit 4b498871ed54b726748d95808a2a840e8a51735c. The change was not properly implementing previous behaviour in presence of multiple sockets reporting to the same set of attributes. Instead of summing their usage it was reporting only the latest one. --- lib/supavisor/monitoring/telem.ex | 10 +++++----- lib/supavisor/monitoring/tenant.ex | 14 ++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/supavisor/monitoring/telem.ex b/lib/supavisor/monitoring/telem.ex index 9c814511..74d1a40d 100644 --- a/lib/supavisor/monitoring/telem.ex +++ b/lib/supavisor/monitoring/telem.ex @@ -25,15 +25,15 @@ defmodule Supavisor.Monitoring.Telem do @spec network_usage(:client | :db, Supavisor.sock(), Supavisor.id(), map()) :: {:ok | :error, map()} - def network_usage(type, {mod, socket}, id, _stats) do + def network_usage(type, {mod, socket}, id, stats) do network_usage_disable do mod = if mod == :ssl, do: :ssl, else: :inet case mod.getstat(socket, [:recv_oct, :send_oct]) do {:ok, [{:recv_oct, recv_oct}, {:send_oct, send_oct}]} -> stats = %{ - send_oct: send_oct, - recv_oct: recv_oct + send_oct: send_oct - stats.send_oct, + recv_oct: recv_oct - stats.recv_oct } {{ptype, tenant}, user, mode, db_name, search_path} = id @@ -51,11 +51,11 @@ defmodule Supavisor.Monitoring.Telem do } ) - {:ok, %{}} + {:ok, %{recv_oct: recv_oct, send_oct: send_oct}} {:error, reason} -> Logger.error("Failed to get socket stats: #{inspect(reason)}") - {:error, %{}} + {:error, stats} end end end diff --git a/lib/supavisor/monitoring/tenant.ex b/lib/supavisor/monitoring/tenant.ex index fe3c5a17..767aa278 100644 --- a/lib/supavisor/monitoring/tenant.ex +++ b/lib/supavisor/monitoring/tenant.ex @@ -81,25 +81,19 @@ defmodule Supavisor.PromEx.Plugins.Tenant do peep_bucket_calculator: Buckets ] ), - last_value( + sum( [:supavisor, :client, :network, :recv], event_name: [:supavisor, :client, :network, :stat], measurement: :recv_oct, description: "The total number of bytes received by clients.", - tags: @tags, - reporter_options: [ - prometheus_type: :sum - ] + tags: @tags ), - last_value( + sum( [:supavisor, :client, :network, :send], event_name: [:supavisor, :client, :network, :stat], measurement: :send_oct, description: "The total number of bytes sent by clients.", - tags: @tags, - reporter_options: [ - prometheus_type: :sum - ] + tags: @tags ), counter( [:supavisor, :client, :queries, :count],