Skip to content

Commit

Permalink
[RTC-474] Expand room metrics (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgfn authored Mar 6, 2024
1 parent 19b6df0 commit 3bda0a3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
9 changes: 7 additions & 2 deletions lib/jellyfish/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ defmodule Jellyfish.Room do
:ok = Engine.add_endpoint(state.engine_pid, peer.engine_endpoint, id: peer_id)

Logger.info("Peer #{inspect(peer_id)} connected")
:telemetry.execute([:jellyfish, :room], %{peer_connects: 1}, %{room_id: state.id})

{:ok, state}

Expand Down Expand Up @@ -433,6 +434,7 @@ defmodule Jellyfish.Room do
{peer_id, peer} ->
:ok = Engine.remove_endpoint(state.engine_pid, peer_id)
Event.broadcast_server_notification({:peer_disconnected, state.id, peer_id})
:telemetry.execute([:jellyfish, :room], %{peer_disconnects: 1}, %{room_id: state.id})
peer = %{peer | status: :disconnected, socket_pid: nil}

put_in(state, [:peers, peer_id], peer)
Expand Down Expand Up @@ -737,11 +739,14 @@ defmodule Jellyfish.Room do

Logger.info("Removed peer #{inspect(peer_id)} from room #{inspect(state.id)}")

if peer.status == :connected and reason == :peer_removed,
do: Event.broadcast_server_notification({:peer_disconnected, state.id, peer_id})
if peer.status == :connected and reason == :peer_removed do
Event.broadcast_server_notification({:peer_disconnected, state.id, peer_id})
:telemetry.execute([:jellyfish, :room], %{peer_disconnects: 1}, %{room_id: state.id})
end

with {:peer_crashed, crash_reason} <- reason do
Event.broadcast_server_notification({:peer_crashed, state.id, peer_id, crash_reason})
:telemetry.execute([:jellyfish, :room], %{peer_crashes: 1}, %{room_id: state.id})
end

state
Expand Down
12 changes: 3 additions & 9 deletions lib/jellyfish/room_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ defmodule Jellyfish.RoomService do
[:jellyfish, :room],
%{
peers: peer_count,
peer_time_total: peer_count * @metric_interval_in_seconds
peer_time: peer_count * @metric_interval_in_seconds,
duration: @metric_interval_in_seconds
},
%{room_id: room.id}
)
Expand Down Expand Up @@ -223,14 +224,7 @@ defmodule Jellyfish.RoomService do
end

defp clear_room_metrics(room_id) do
:telemetry.execute(
[:jellyfish, :room],
%{
peers: 0,
peer_time_total: 0
},
%{room_id: room_id}
)
:telemetry.execute([:jellyfish, :room], %{peers: 0}, %{room_id: room_id})
end

defp find_best_node(node_resources) do
Expand Down
47 changes: 31 additions & 16 deletions lib/jellyfish_web/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,52 @@ defmodule JellyfishWeb.Telemetry do
description: "Total HTTP traffic sent (bytes)"
),
last_value("jellyfish.rooms",
description: "Amount of rooms currently present in Jellyfish"
description: "Number of rooms currently present in Jellyfish"
),

# FIXME: Prometheus warns about using labels to store dimensions with high cardinality,
# such as UUIDs. For more information refer here: https://prometheus.io/docs/practices/naming/#labels
last_value("jellyfish.room.peers",
tags: [:room_id],
description: "Amount of peers currently present in a given room"
description: "Number of peers currently present in a given room"
),
sum("jellyfish.room.peer_time.total.seconds",
event_name: [:jellyfish, :room],
measurement: :peer_time_total,
measurement: :peer_time,
tags: [:room_id],
description: "Total peer time accumulated for a given room (seconds)"
),
sum("jellyfish.room.duration.seconds",
event_name: [:jellyfish, :room],
measurement: :duration,
tags: [:room_id],
description: "Duration of a given room (seconds)"
),
sum("jellyfish.room.peer_connects.total",
event_name: [:jellyfish, :room],
measurement: :peer_connects,
tags: [:room_id],
description:
"Number of PeerConnected events emitted during the lifetime of a given room"
),
sum("jellyfish.room.peer_disconnects.total",
event_name: [:jellyfish, :room],
measurement: :peer_disconnects,
tags: [:room_id],
description:
"Number of PeerDisconnected events emitted during the lifetime of a given room"
),
sum("jellyfish.room.peer_crashes.total",
event_name: [:jellyfish, :room],
measurement: :peer_crashes,
tags: [:room_id],
description: "Number of PeerCrashed events emitted during the lifetime of a given room"
)
]
end

def default_webrtc_metrics() do
:telemetry.execute(
[Membrane.ICE, :ice, :payload, :sent],
%{
bytes: 0
}
)

:telemetry.execute(
[Membrane.ICE, :ice, :payload, :received],
%{
bytes: 0
}
)
:telemetry.execute(@ice_sent_event, %{bytes: 0})
:telemetry.execute(@ice_received_event, %{bytes: 0})
end
end

0 comments on commit 3bda0a3

Please sign in to comment.