diff --git a/lib/supavisor/monitoring/telem.ex b/lib/supavisor/monitoring/telem.ex index 9c814511..02a60a85 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 - Map.get(stats, :send_oct, 0), + recv_oct: recv_oct - Map.get(stats, :recv_oct, 0) } {{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],