Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display the count of connected tenants in metrics #418

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/realtime/monitoring/prom_ex.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Realtime.PromEx do
alias Realtime.PromEx.Plugins.{OsMon, Phoenix}
alias Realtime.PromEx.Plugins.{OsMon, Phoenix, Tenants}

@moduledoc """
Be sure to add the following to finish setting up PromEx:
Expand Down Expand Up @@ -70,7 +70,8 @@ defmodule Realtime.PromEx do
# {Plugins.Ecto, poll_rate: poll_rate, metric_prefix: [:ecto]},
# Plugins.Oban,
# Plugins.PhoenixLiveView
{OsMon, poll_rate: poll_rate}
{OsMon, poll_rate: poll_rate},
{Tenants, poll_rate: poll_rate}
]
end

Expand Down
50 changes: 50 additions & 0 deletions lib/realtime/monitoring/tenants.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Realtime.PromEx.Plugins.Tenants do
@moduledoc false

use PromEx.Plugin
require Logger

@event_connected [:prom_ex, :plugin, :tenants, :connected]

@impl true
def polling_metrics(opts) do
poll_rate = Keyword.get(opts, :poll_rate)

[
metrics(poll_rate)
]
end

defp metrics(poll_rate) do
Polling.build(
:realtime_tenants_events,
poll_rate,
{__MODULE__, :execute_metrics, []},
[
last_value(
[:tenants, :connected],
event_name: @event_connected,
description: "The total count of connected tenants.",
measurement: :connected
)
]
)
end

def execute_metrics() do
connected =
if Enum.member?(:syn.node_scopes(), Extensions.PostgresCdcRls) do
:syn.local_registry_count(Extensions.PostgresCdcRls)
else
-1
end

execute_metrics(@event_connected, %{
connected: connected
})
end

defp execute_metrics(event, metrics) do
:telemetry.execute(event, metrics, %{})
end
end