00. 目录
01. 命令概述
nstat命令是一个简单的监视内核的SNMP计数器和网络接口状态的实用工具 。
02. 命令格式
格式:nstat [选项]
03. 常用选项
-z 显示0计数器
-h 显示帮助信息
-V 显示指令版本信息
-r 清零历史统计
-n 不显示任何内容,仅更新历史
-a 显示计数器的绝对值
-s 不更新历史
-d 以守护进程的方式运行本指令
-j 以json格式打印结果
04. 参考示例
4.1 查询内核的SNMP计数器和网络接口状态
[root@localhost ~]# nstat
#kernel
IpInReceives 773 0.0
IpInDelivers 773 0.0
IpOutRequests 145 0.0
TcpInSegs 203 0.0
TcpOutSegs 146 0.0
UdpInDatagrams 295 0.0
UdpOutDatagrams 2 0.0
Ip6InReceives 1 0.0
Ip6InDelivers 1 0.0
Ip6InMcastPkts 1 0.0
Ip6InOctets 72 0.0
Ip6InMcastOctets 72 0.0
Ip6InNoECTPkts 1 0.0
Icmp6InMsgs 1 0.0
Icmp6InNeighborAdvertisements 1 0.0
Icmp6InType136 1 0.0
TcpExtDelayedACKs 1 0.0
TcpExtTCPHPHits 68 0.0
TcpExtTCPPureAcks 46 0.0
TcpExtTCPHPAcks 56 0.0
TcpExtTCPAutoCorking 4 0.0
TcpExtTCPOrigDataSent 137 0.0
IpExtInMcastPkts 290 0.0
IpExtOutMcastPkts 1 0.0
IpExtInBcastPkts 280 0.0
IpExtInOctets 75274 0.0
IpExtOutOctets 31223 0.0
IpExtInMcastOctets 22608 0.0
IpExtOutMcastOctets 67 0.0
IpExtInBcastOctets 33258 0.0
IpExtInNoECTPkts 773 0.0
[root@localhost ~]#
4.2 以json格式打印结果
[root@localhost ~]# nstat -j
{"kernel":{"IpInReceives":47,"IpInDelivers":47,"IpOutRequests":9,"TcpInSegs":15,"TcpOutSegs":10,"UdpInDatagrams":24,"TcpExtTCPHPHits":3,"TcpExtTCPPureAcks":4,"TcpExtTCPHPAcks":4,"TcpExtTCPAutoCorking":1,"TcpExtTCPOrigDataSent":10,"IpExtInMcastPkts":23,"IpExtInBcastPkts":9,"IpExtInOctets":4396,"IpExtOutOctets":2984,"IpExtInMcastOctets":1368,"IpExtInBcastOctets":1704,"IpExtInNoECTPkts":47}}
[root@localhost ~]#
4.3 不更新历史
[root@localhost ~]# nstat -s
nstat: history is stale, ignoring it.
#12240.1804289383 sampling_interval=2 time_const=60
IpInReceives 879168 1.5
IpInDelivers 879113 1.5
IpOutRequests 3269 0.3
IpOutNoRoutes 16 0.0
IcmpInMsgs 65 0.0
IcmpInRedirects 65 0.0
IcmpOutMsgs 11 0.0
IcmpOutDestUnreachs 11 0.0
IcmpMsgInType5 65 0.0
IcmpMsgOutType3 11 0.0
TcpActiveOpens 8 0.0
4.4 显示计数器的绝对值
[root@localhost ~]# nstat -a
nstat: history is stale, ignoring it.
#12240.1804289383 sampling_interval=2 time_const=60
IpInReceives 879208 1.4
IpInDelivers 879153 1.4
IpOutRequests 3281 0.4
IpOutNoRoutes 16 0.0
IcmpInMsgs 65 0.0
IcmpInRedirects 65 0.0
IcmpOutMsgs 11 0.0
IcmpOutDestUnreachs 11 0.0
IcmpMsgInType5 65 0.0
IcmpMsgOutType3 11 0.0
TcpActiveOpens 8 0.0
4.5 清零历史统计
[root@localhost ~]# nstat -r
#12240.1804289383 sampling_interval=2 time_const=60
IpInReceives 879249 1.0
IpInDelivers 879194 1.0
IpOutRequests 3289 0.1
IpOutNoRoutes 16 0.0
IcmpInMsgs 65 0.0
IcmpInRedirects 65 0.0
IcmpOutMsgs 11 0.0
IcmpOutDestUnreachs 11 0.0
IcmpMsgInType5 65 0.0
IcmpMsgOutType3 11 0.0