1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright (c) 2023 Robin Jarry 3 4RX_PACKETS = "rx_packets" 5RX_BYTES = "rx_bytes" 6RX_MISSED = "rx_missed" 7RX_NOMBUF = "rx_nombuf" 8RX_ERRORS = "rx_errors" 9TX_PACKETS = "tx_packets" 10TX_BYTES = "tx_bytes" 11TX_ERRORS = "tx_errors" 12 13 14def info() -> "dict[Name, tuple[Description, Type]]": 15 return { 16 RX_PACKETS: ("Number of successfully received packets.", "counter"), 17 RX_BYTES: ("Number of successfully received bytes.", "counter"), 18 RX_MISSED: ( 19 "Number of packets dropped by the HW because Rx queues are full.", 20 "counter", 21 ), 22 RX_NOMBUF: ("Number of Rx mbuf allocation failures.", "counter"), 23 RX_ERRORS: ("Number of erroneous received packets.", "counter"), 24 TX_PACKETS: ("Number of successfully transmitted packets.", "counter"), 25 TX_BYTES: ("Number of successfully transmitted bytes.", "counter"), 26 TX_ERRORS: ("Number of packet transmission failures.", "counter"), 27 } 28 29 30def metrics(sock: "TelemetrySocket") -> "list[tuple[Name, Value, Labels]]": 31 out = [] 32 for port_id in sock.cmd("/ethdev/list"): 33 port = sock.cmd("/ethdev/info", port_id) 34 stats = sock.cmd("/ethdev/stats", port_id) 35 labels = {"port": port["name"]} 36 out += [ 37 (RX_PACKETS, stats["ipackets"], labels), 38 (RX_PACKETS, stats["ipackets"], labels), 39 (RX_BYTES, stats["ibytes"], labels), 40 (RX_MISSED, stats["imissed"], labels), 41 (RX_NOMBUF, stats["rx_nombuf"], labels), 42 (RX_ERRORS, stats["ierrors"], labels), 43 (TX_PACKETS, stats["opackets"], labels), 44 (TX_BYTES, stats["obytes"], labels), 45 (TX_ERRORS, stats["oerrors"], labels), 46 ] 47 return out 48