解释 netstat -s 的统计数据

解释 netstat -s 的统计数据

我在家里的 Ubuntu 机器上运行 netstat -s 来获取网络接口统计信息。打印出一堆数字,如下所示:

Ip:
    10256 total packets received
    8 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    10247 incoming packets delivered
    8918 requests sent out
    63 dropped because of missing route
Icmp:
    0 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
    55 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 55
IcmpMsg:
        OutType3: 55
Tcp:
    378 active connections openings
    0 passive connection openings
    5 failed connection attempts
    17 connection resets received
    30 connections established
    8478 segments received
    8223 segments send out
    26 segments retransmited
    0 bad segments received.
    33 resets sent
Udp:
    911 packets received
    55 packets to unknown port received.
    0 packet receive errors
    893 packets sent
UdpLite:
TcpExt:
    85 TCP sockets finished time wait in fast timer
    182 delayed acks sent
    Quick ack mode was activated 11 times
    16 packets directly queued to recvmsg prequeue.
    22002 bytes directly received in process context from prequeue
    5397 packet headers predicted
    11 packets header predicted and directly queued to user
    922 acknowledgments not containing data payload received
    477 predicted acknowledgments
    2 congestion windows recovered without slow start by DSACK
    16 congestion windows recovered without slow start after partial ack
    24 other TCP timeouts
    11 DSACKs sent for old packets
    11 DSACKs received
    8 connections reset due to unexpected data
    7 connections reset due to early user close
    TCPDSACKIgnoredNoUndo: 1
    TCPSackShiftFallback: 18
    IPReversePathFilter: 1
IpExt:
    InMcastPkts: 65
    OutMcastPkts: 21
    InBcastPkts: 836
    InOctets: 8228049
    OutOctets: 1814741
    InMcastOctets: 13209
    OutMcastOctets: 4122
    InBcastOctets: 102775

有什么方法可以确定收集这些统计数据的时间段吗?

答案1

看着netstat 相关源代码或者使用strace -e open netstat -s,可以看到上述信息是从/proc/net/snmp和中获取的/proc/net/netstat。此 proc-fs 信息由 Linux 网络堆栈填充,并在中初始化净/ipv4/proc.c. 内核的这一部分如果启用,则会在内核启动时启动其功能。

由于您没有指定您正在寻找的答案的准确性,长话短说,我想您可能会对此感到满意:

uptime

您还可以使用类似下面的方法以秒为单位获取它:

set -- $(grep btime /proc/stat) && btime = $2
bc -l < <(printf "%s - %s\n" "$(date +%s)" "$btime")

相关内容