ObserverWeb.Network (Observer Web v0.2.6)

View Source

Samples a node's network endpoints: inet ports (driver-based gen_tcp/gen_udp/gen_sctp connections) with their transfer statistics, and NIF-based socket module sockets, which port listings miss entirely - the web equivalent of observer_cli's Network pane and the observer GUI's Ports/Sockets tabs.

Sampling delegates to :observer_backend.get_port_list/0 and get_socket_list/0 (runtime_tools, already required on every node for :dbg tracing): one RPC round trip each returns every endpoint's metadata and counters, regardless of the observer_web version on the observed node.

Transfer counters (recv_oct/send_oct from inet:getstat/1) are cumulative, so ranking by throughput uses the delta between two consecutive samples (rank_ports/4 with the previous sample's counters map) - the first sample ranks by the cumulative value.

Summary

Functions

Extracts the %{port => {recv_oct, send_oct}} map used as previous_counters for the next rank_ports/4 call.

Ranks a sample's inet ports by sort_by, keeping the top limit rows.

Collects one sample of the node's inet ports and NIF sockets.

Types

port_row()

@type port_row() :: %{
  port: port(),
  name: String.t(),
  owner_label: String.t(),
  local: String.t(),
  remote: String.t(),
  recv_oct: non_neg_integer(),
  send_oct: non_neg_integer(),
  recv_diff: non_neg_integer(),
  send_diff: non_neg_integer(),
  queue_size: non_neg_integer(),
  memory: non_neg_integer(),
  inet: Keyword.t()
}

socket_row()

@type socket_row() :: %{
  id_str: String.t(),
  kind: term(),
  domain: term(),
  type: term(),
  protocol: term(),
  read_bytes: non_neg_integer(),
  write_bytes: non_neg_integer(),
  info: map()
}

Functions

counters_by_port(ports)

@spec counters_by_port([port_row()]) :: %{
  optional(port()) => {non_neg_integer(), non_neg_integer()}
}

Extracts the %{port => {recv_oct, send_oct}} map used as previous_counters for the next rank_ports/4 call.

rank_ports(ports, sort_by, limit, previous_counters \\ %{})

@spec rank_ports([port_row()], :recv | :send | :total, pos_integer(), map()) :: [
  port_row()
]

Ranks a sample's inet ports by sort_by, keeping the top limit rows.

previous_counters is a %{port => {recv_oct, send_oct}} map from the preceding sample; each row's recv_diff/send_diff become the delta since then (ports not present before - or on the very first sample - keep their cumulative counters).

sample(node)

@spec sample(node()) ::
  {:ok, %{ports: [port_row()], sockets: [socket_row()]}} | {:error, term()}

Collects one sample of the node's inet ports and NIF sockets.

Nodes running an OTP release without get_socket_list/0 degrade to an empty socket list rather than an error - the inet ports are still reported.