Skip to content

Commit

Permalink
fix: properly compute socket usage
Browse files Browse the repository at this point in the history
This partially reverts commit 4b49887.

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.
  • Loading branch information
hauleth committed Dec 13, 2024
1 parent ce0a580 commit 11f3f10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/supavisor/monitoring/telem.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,11 +51,11 @@ defmodule Supavisor.Monitoring.Telem do
}
)

{:ok, %{}}
{:ok, stats}

{:error, reason} ->
Logger.error("Failed to get socket stats: #{inspect(reason)}")
{:error, %{}}
{:error, stats}
end
end
end
Expand Down
14 changes: 4 additions & 10 deletions lib/supavisor/monitoring/tenant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 11f3f10

Please sign in to comment.