系统管理指南:网络服务

第 30 章 监视网络性能(任务)

本章介绍如何监视网络性能。以下是本章中的逐步说明列表。

监视网络性能

表 30–1 中介绍了可用于监视网络性能的命令。

表 30–1 网络监视命令

命令 

说明 

ping

查看网络中主机的响应。 

spray

测试包大小的可靠性。此命令可指出网络将延迟包还是删除包。 

snoop

从网络中捕获包,并跟踪每台客户机对每台服务器的调用。 

netstat

显示网络状态,包括用于 TCP/IP 流量的接口的状态、IP 路由表以及用于 UDPTCPICMPIGMP 的按协议的统计信息。

nfsstat

显示可用于确定 NFS 问题的服务器和客户机统计信息的汇总。 

如何检查网络中主机的响应

使用 ping 命令可检查网络中主机的响应。


$ ping hostname

如果您怀疑存在物理问题,可以使用 ping 确定网络中若干个主机的响应时间。如果某一主机的响应不是您期望的,则可对该主机进行研究。物理问题可能由以下原因引起:

有关此命令的更多信息,请参见 ping(1M)


示例 30–1 检查网络中主机的响应

最简单版本的 ping 可将单个包发送到网络中的主机。如果 ping 接收到正确的响应,该命令将列显消息 host is alive


$ ping elvis

elvis is alive

使用 -s 选项时,ping 可以每秒向主机发送一个数据报。然后,该命令将列显每个响应以及往返所需的时间。以下为示例。


$ ping -s pluto

64 bytes from pluto (123.456.78.90): icmp_seq=0. time=10. ms

64 bytes from pluto (123.456.78.90): icmp_seq=5. time=0. ms

64 bytes from pluto (123.456.78.90): icmp_seq=6. time=0. ms

^C

----pluto PING Statistics----

8 packets transmitted, 8 packets received, 0% packet loss

 

round-trip (ms) min/avg/max = 0/2/10

如何向网络中的主机发送包

spray 命令可以测试包大小的可靠性。


$ spray [ -c count -d interval -l packet_size] hostname
-i count

要发送的包的数目。

-d interval

在两次发送包之间暂停的微秒数。如果不使用延迟,则可能耗尽缓冲区。

-l packet_size

包的大小。

hostname

要发送包的系统。

有关此命令的更多信息,请参见 spray(1M)


示例 30–2 向网络中的主机发送包

以下示例将向主机 (-c 100) 发送 100 个包,包大小为 2048 字节 (-l 2048 )。发送包时,每次成组传输之间的延迟时间为 20 微秒 (-d 20)。


$ spray -c 100 -d 20 -l 2048 pluto

sending 100 packets of length 2048 to pluto ...

no packets dropped by pluto

279 packets/sec, 573043 bytes/sec

如何从网络中捕获包

要从网络中捕获包并跟踪每台客户机对每台服务器的调用,请使用 snoop。此命令提供了精确的时间标记,因此可以快速隔离一些网络性能问题。有关更多信息,请参见 snoop(1M)


# snoop

删除包可能是由缓冲区空间不足或 CPU 过载引起的。

如何检查网络状态

要显示网络状态信息,例如有关网络接口状态、路由表和各种协议的统计信息,请使用 netstat 命令。


$ netstat [-i] [-r] [-s]
-i

显示 TCP/IP 接口的状态

-r

显示 IP 路由表

-s

显示 UDPTCPICMPIGMP 协议的统计信息

有关更多信息,请参见 netstat(1M)

示例-检查网络状态

以下示例显示 netstat -i 命令的输出,其中显示了用于 TCP/IP 流量的接口的状态。


$ netstat -i

Name  Mtu  Net/Dest    Address      Ipkts  Ierrs Opkts  Oerrs Collis Queue

lo0   8232 software    localhost     1280   0     1280     0       0    0

eri0   1500 loopback    venus      1628480   0   347070    16   39354    0

此输出显示了机器在每个接口中传输和接收的包数。对于具有活动网络通信流量的机器而言,IpktsOpkts 都应持续增加。

将冲突计数 (Collis) 除以传出的包数 (Opkts),以计算网络冲突率。在上一示例中,冲突率为 11%。如果网络范围内的冲突率大于 5% 至 10 %,则表示可能存在问题。

将输入错误数除以输入包的总数 (Ierrs/Ipkts),以计算输入包的错误率。输出包的错误率等于输出错误数除以输出包的总数 (Oerrs/Opkts)。如果输入错误率较高(高于 0.25%)则主机可能在删除包。

以下示例显示 netstat -s 命令的输出,其中显示了 UDPTCPICMPIGMP 协议的按协议的统计信息。


UDP

    udpInDatagrams      =196543    udpInErrors         =     0

    udpOutDatagrams     =187820

 

TCP

    tcpRtoAlgorithm     =     4    tcpRtoMin           =   200

    tcpRtoMax           = 60000    tcpMaxConn          =    -1

    tcpActiveOpens      = 26952    tcpPassiveOpens     =   420

    tcpAttemptFails     =  1133    tcpEstabResets      =     9

    tcpCurrEstab        =    31    tcpOutSegs          =3957636

    tcpOutDataSegs      =2731494   tcpOutDataBytes     =1865269594

    tcpRetransSegs      = 36186    tcpRetransBytes     =3762520

    tcpOutAck           =1225849   tcpOutAckDelayed    =165044

    tcpOutUrg           =     7    tcpOutWinUpdate     =   315

    tcpOutWinProbe      =     0    tcpOutControl       = 56588

    tcpOutRsts          =   803    tcpOutFastRetrans   =   741

    tcpInSegs           =4587678

    tcpInAckSegs        =2087448   tcpInAckBytes       =1865292802

    tcpInDupAck         =109461    tcpInAckUnsent      =     0

    tcpInInorderSegs    =3877639   tcpInInorderBytes   =-598404107

    tcpInUnorderSegs    = 14756    tcpInUnorderBytes   =17985602

    tcpInDupSegs        =    34    tcpInDupBytes       = 32759

    tcpInPartDupSegs    =   212    tcpInPartDupBytes   =134800

    tcpInPastWinSegs    =     0    tcpInPastWinBytes   =     0

    tcpInWinProbe       =   456    tcpInWinUpdate      =     0

    tcpInClosed         =    99    tcpRttNoUpdate      =  6862

    tcpRttUpdate        =435097    tcpTimRetrans       = 15065

    tcpTimRetransDrop   =    67    tcpTimKeepalive     =   763

    tcpTimKeepaliveProbe=     1    tcpTimKeepaliveDrop =     0



IP

    ipForwarding        =     2    ipDefaultTTL        =   255

    ipInReceives        =11757234  ipInHdrErrors       =     0

    ipInAddrErrors      =     0    ipInCksumErrs       =     0

    ipForwDatagrams     =     0    ipForwProhibits     =     0

    ipInUnknownProtos   =     0    ipInDiscards        =     0

    ipInDelivers        =4784901   ipOutRequests       =4195180

    ipOutDiscards       =     0    ipOutNoRoutes       =     0

    ipReasmTimeout      =    60    ipReasmReqds        =  8723

    ipReasmOKs          =  7565    ipReasmFails        =  1158

    ipReasmDuplicates   =     7    ipReasmPartDups     =     0

    ipFragOKs           = 19938    ipFragFails         =     0

    ipFragCreates       =116953    ipRoutingDiscards   =     0

    tcpInErrs           =     0    udpNoPorts          =6426577

    udpInCksumErrs      =     0    udpInOverflows      =   473

    rawipInOverflows    =     0



ICMP

    icmpInMsgs          =490338    icmpInErrors        =     0

    icmpInCksumErrs     =     0    icmpInUnknowns      =     0

    icmpInDestUnreachs  =   618    icmpInTimeExcds     =   314

    icmpInParmProbs     =     0    icmpInSrcQuenchs    =     0

    icmpInRedirects     =   313    icmpInBadRedirects  =     5

    icmpInEchos         =   477    icmpInEchoReps      =    20

    icmpInTimestamps    =     0    icmpInTimestampReps =     0

    icmpInAddrMasks     =     0    icmpInAddrMaskReps  =     0

    icmpInFragNeeded    =     0    icmpOutMsgs         =   827

    icmpOutDrops        =   103    icmpOutErrors       =     0

    icmpOutDestUnreachs =    94    icmpOutTimeExcds    =   256

    icmpOutParmProbs    =     0    icmpOutSrcQuenchs   =     0

    icmpOutRedirects    =     0    icmpOutEchos        =     0

    icmpOutEchoReps     =   477    icmpOutTimestamps   =     0

    icmpOutTimestampReps=     0    icmpOutAddrMasks    =     0

    icmpOutAddrMaskReps =     0    icmpOutFragNeeded   =     0

    icmpInOverflows     =     0



IGMP:

        0 messages received

        0 messages received with too few bytes

        0 messages received with bad checksum

        0 membership queries received

        0 membership queries received with invalid field(s)

        0 membership reports received

        0 membership reports received with invalid field(s)

        0 membership reports received for groups to which we belong

        0 membership reports sent

以下示例显示 netstat -r 命令的输出,其中显示了 IP 路由表。


Routing Table:

  Destination        Gateway           Flags  Ref   Use    Interface

------------------ -------------------- ----- ----- ------ ---------

localhost            localhost             UH       0   2817  lo0

earth-bb             pluto                 U        3  14293  eri0

224.0.0.0            pluto                 U        3      0  eri0

default              mars-gate             UG       0  14142  

 

表 30–2 中介绍了 netstat -r 报告中的字段。

表 30–2 netstat -r 命令的输出

字段名 

 

说明 

Flags

U

G

H

D

路由向上。 

路由通过网关。 

路由到主机。 

路由是使用重定向动态创建的。 

Ref

 

显示共享相同链路层的当前路由数。 

Use

 

表示发出的包的数目。 

Interface

 

列出用于路由的网络接口。  

如何显示 NFS 服务器和客户机统计信息

NFS 分布式文件服务使用远程过程调用 (remote procedure call, RPC) 工具来将本地命令转换为对远程主机的请求。远程过程调用是同步的。在服务器完成调用并返回结果之前,客户机应用程序将被阻塞或暂停。影响 NFS 性能的一个主要因素是重新传输率。

如果文件服务器不能对客户机的请求做出响应,则客户机在退出之前将重新传输该请求,重新传输的次数是指定次数。每次重新传输都会产生系统开销并增加网络通信流量。过多的重新传输会引起网络性能问题。如果重新传输率很高,可检查是否存在以下问题:

表 30–3 中介绍了用于显示客户机和服务器统计信息的 nfsstat 选项。

表 30–3 用于显示客户机/服务器统计信息的命令

命令 

显示 

nfsstat -c

客户机统计信息 

nfsstat -s

服务器统计信息 

netstat -m

每个文件系统的网络统计信息 

使用 nfsstat -c 可以显示客户机统计信息,使用 nfsstat -s 可以显示服务器统计信息。使用 netstat -m 可以显示每个文件系统的网络统计信息。有关更多信息,请参见 nfsstat(1M)

示例-显示 NFS 服务器和客户机统计信息

以下示例显示客户机 pluto 的 RPC 和 NFS 数据。


$ nfsstat -c



Client rpc:

Connection oriented:

calls    badcalls  badxids  timeouts newcreds  badverfs   timers     

1595799  1511      59       297      0         0          0          

cantconn nomem     interrupts 

1198      0         7          

Connectionless:

calls    badcalls  retrans  badxids  timeouts  newcreds   badverfs   

80785    3135      25029    193      9543      0          0          

timers   nomem     cantsend   

17399    0         0          



Client nfs:

calls    badcalls  clgets   cltoomany  

1640097  3112      1640097  0          

Version 2: (46366 calls)

null     getattr   setattr  root     lookup     readlink  read       

0 0%     6589 14%  2202 4%  0 0%     11506 24%  0 0%      7654 16%   

wrcache  write     create   remove   rename     link      symlink    

0 0%     13297 28% 1081 2%  0 0%     0 0%       0 0%      0 0%       

mkdir    rmdir     readdir  statfs     

24 0%    0 0%      906 1%   3107 6%    

Version 3: (1585571 calls)

null    getattr    setattr  lookup     access     readlink  read     

0 0%    508406 32% 10209 0% 263441 16% 400845 25% 3065 0%  117959 7%

write    create     mkdir    symlink    mknod    remove   rmdir 

69201 4% 7615 0%    42 0%    16 0%      0 0%     7875 0%  51 0%      

rename   link       readdir  readdir+   fsstat   fsinfo   pathconf   

929 0%   597 0%     3986 0%  185145 11% 942 0%   300 0%   583 0%     

commit     

4364 0%    

 

Client nfs_acl:

Version 2: (3105 calls)

null       getacl     setacl     getattr    access     

0 0%       0 0%       0 0%       3105 100%  0 0%       

Version 3: (5055 calls)

null       getacl     setacl     

0 0%       5055 100%  0 0%    

表 30–4 中介绍了 nfsstat -c 命令的输出。

表 30–4 nfsstat -c 命令的输出

字段 

说明 

calls

发送的调用总数。 

badcalls

RPC 拒绝的调用总数。 

retrans

重新传输的总数。对于此客户机,重新传输率小于 1%,或者 6888 次调用中有 10 次超时。这些重新传输可能是由临时故障引起的。更高的比率表明可能存在问题。 

badxid

对一个 NFS 请求收到重复确认的次数。 

timeout

超时的调用数。 

wait

因没有可用的客户机句柄,调用必须等待的次数。 

newcred

必须刷新验证信息的次数。 

timers

超时值大于或等于为调用指定的超时值的次数。 

readlink

使 read 成为符号链接的次数。如果此值很高(超过 10 %)则可能存在过多符号链接。

以下示例显示 nfsstat -m 命令的输出。


pluto$ nfsstat -m

/usr/man from pluto:/export/svr4/man

Flags: vers=2,proto=udp,auth=unix,hard,intr,dynamic,

        rsize=8192, wsize=8192,retrans=5

 Lookups: srtt=13 (32ms), dev=10 (50ms), cur=6 (120ms)

 All:     srtt=13 (32ms), dev=10 (50ms), cur=6 (120ms)

nfsstat -m 命令的输出以毫秒显示,表 30–5 中对其进行了介绍。

表 30–5 nfsstat -m 命令的输出

字段 

说明 

srtt

往返时间的平滑平均值 

dev

平均偏差 

cur

当前的“预期”响应时间 

如果怀疑网络的硬件组件存在问题,则需要仔细检查电缆和连接器。