diff --git a/lib/jellyfish/room.ex b/lib/jellyfish/room.ex index 0434716b..dd3abd87 100644 --- a/lib/jellyfish/room.ex +++ b/lib/jellyfish/room.ex @@ -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} @@ -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) @@ -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 diff --git a/lib/jellyfish/room_service.ex b/lib/jellyfish/room_service.ex index a7723274..350e1c35 100644 --- a/lib/jellyfish/room_service.ex +++ b/lib/jellyfish/room_service.ex @@ -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} ) @@ -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 diff --git a/lib/jellyfish_web/telemetry.ex b/lib/jellyfish_web/telemetry.ex index 5b31485d..8cdef662 100644 --- a/lib/jellyfish_web/telemetry.ex +++ b/lib/jellyfish_web/telemetry.ex @@ -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