Skip to content

Commit

Permalink
add nodes_connected metric (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne authored Jun 10, 2024
1 parent 17a0073 commit 31f8741
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions lib/archethic/p2p.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ defmodule Archethic.P2P do
end
end

@doc """
Called by the telemetry poller
"""
def nodes_connected_count() do
nodes_connected =
authorized_and_available_nodes()
|> Enum.reject(&(&1.first_public_key == Crypto.first_node_public_key()))
|> Enum.filter(&node_connected?/1)
|> Enum.count()

:telemetry.execute(
[:archethic, :p2p],
%{nodes_connected: nodes_connected}
)
rescue
_ ->
# this will fail at startup because ETS table does not exist yet
:ok
end

@doc """
List the nodes registered.
"""
Expand Down
4 changes: 3 additions & 1 deletion lib/archethic/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ defmodule Archethic.Telemetry do

defp periodic_metrics do
[
{Archethic.Contracts, :maximum_calls_in_queue, []}
{Archethic.Contracts, :maximum_calls_in_queue, []},
{Archethic.P2P, :nodes_connected_count, []}
]
end

Expand Down Expand Up @@ -108,6 +109,7 @@ defmodule Archethic.Telemetry do
buckets: [500, 700, 1000, 1500, 2000, 3000, 5000, 10000]
]
),
last_value("archethic.p2p.nodes_connected"),
distribution("archethic.p2p.send_message.duration",
unit: {:native, :millisecond},
measurement: :duration,
Expand Down

0 comments on commit 31f8741

Please sign in to comment.