Overview
TheProtoCounters function retrieves network statistics for various protocols at the system level. This provides detailed counters for protocol-specific metrics like packets, errors, and retransmissions.
Functions
Parameters
List of protocol names to query. If empty, all available protocols are returned.Available protocols:
"ip"- Internet Protocol statistics"icmp"- Internet Control Message Protocol"icmpmsg"- ICMP message type statistics"tcp"- Transmission Control Protocol"udp"- User Datagram Protocol"udplite"- UDP-Lite protocol
Context for cancellation and timeout control
Returns
Returns a slice ofProtoCountersStat structures containing protocol statistics.
ProtoCountersStat Structure
TheProtoCountersStat struct contains statistics for a specific network protocol.
Fields
The name of the protocol (e.g., “tcp”, “udp”, “ip”, “icmp”).
Map of statistic names to their values. The available statistics vary by protocol.
Protocol Statistics
TCP Statistics
Common TCP statistics include:RtoAlgorithm- Retransmission timeout algorithmRtoMin- Minimum RTO valueRtoMax- Maximum RTO valueMaxConn- Maximum number of connectionsActiveOpens- Number of active connection openingsPassiveOpens- Number of passive connection openingsAttemptFails- Number of failed connection attemptsEstabResets- Number of resets on established connectionsCurrEstab- Current established connectionsInSegs- Segments receivedOutSegs- Segments sentRetransSegs- Segments retransmittedInErrs- Segments received with errorsOutRsts- Reset segments sent
UDP Statistics
Common UDP statistics include:InDatagrams- Datagrams receivedNoPorts- Datagrams to unknown portsInErrors- Datagram receive errorsOutDatagrams- Datagrams sentRcvbufErrors- Receive buffer errorsSndbufErrors- Send buffer errors
IP Statistics
Common IP statistics include:Forwarding- IP forwarding statusDefaultTTL- Default time-to-liveInReceives- Packets receivedInHdrErrors- Packets with header errorsInAddrErrors- Packets with address errorsForwDatagrams- Packets forwardedInUnknownProtos- Packets with unknown protocolsInDiscards- Packets discardedInDelivers- Packets deliveredOutRequests- Packets sentOutDiscards- Outgoing packets discardedOutNoRoutes- Packets discarded due to no route
ICMP Statistics
Common ICMP statistics include:InMsgs- Messages receivedInErrors- Messages with errorsInDestUnreachs- Destination unreachable messagesInTimeExcds- Time exceeded messagesInEchos- Echo requests receivedInEchoReps- Echo replies receivedOutMsgs- Messages sentOutErrors- Messages with errorsOutDestUnreachs- Destination unreachable messages sentOutEchos- Echo requests sentOutEchoReps- Echo replies sent
Usage Examples
Get All Protocol Statistics
Get TCP Statistics Only
Monitor UDP Traffic
Get Multiple Protocol Statistics
Calculate Retransmission Rate
Using Context
Check for Network Errors
Platform Support
Supported
- Linux
- Solaris
- AIX
Not Supported
- FreeBSD
- OpenBSD
- Darwin (macOS)
- Windows
Data Source
On Linux, protocol statistics are typically read from/proc/net/snmp and /proc/net/netstat.
Common Use Cases
- Network performance monitoring
- Detecting packet loss and retransmissions
- Analyzing protocol-specific errors
- Network troubleshooting and diagnostics
- Capacity planning based on protocol usage
- Security monitoring (unusual ICMP activity)
Error Handling
See Also
- I/O Counters - Interface-level I/O statistics
- Connections - Active network connections
- Network Overview - Package overview