是否可以通过命令行了解远程 linux/windows 机器上的网络负载。例如,我们可以获得 CPU 负载,即 CPU 使用率为 75%。
答案1
我无法过多地谈论该问题的 Linux 部分,并且我相信您正在寻找的答案将根据您使用的 Linux 版本而有所不同。
以下是使用 PowerShell 完成的 Windows 部分的答案:
$allCounters = Get-Counter -Counter "\Network Adapter(*)\Bytes Total/sec"
foreach ($adapter in $allCounters.CounterSamples) {
if ($adapter.cookedValue -ne 0) {
$adapterName = $adapter.InstanceName
$adapterMax = (Get-Counter "\Network Adapter($adapterName)\Current Bandwidth").CounterSamples.cookedValue
if ($adapterMax -ne 0) {
$objResult = New-Object -TypeName psobject -Property @{
Name = $adapterName
Load = ($adapter.CookedValue/$adapterMax).ToString("P6")
}
$results+=$objResult
}
}
}
$results
这将返回系统上所有当前活动的适配器并计算其利用率。请记住,Windows 认为的适配器最大容量与基于环境的实际容量可能不是同一个数字。如果您知道接口的实际带宽,则可以用常数值替换 $adapterMax,然后根据该值进行计算(以 bps 为单位)。
对于某些适配器(网桥等),Windows 不会存储带宽值,因此带宽会检查为 0。它非常容易传输流量,但由于它是网桥成员的集合,因此 Windows 不会跟踪最大带宽。
如果您想了解更多有关脚本访问性能指标的信息,请查看此处:MSDN Get-Counter cmdlet 您可以轻松调整相同的脚本来获取远程指标。
答案2
对于 Linux 方面,您可以使用命令netstat
。根据您想要查看的具体内容,您可以使用大量标志。(手册页非常详细。)(开关-s
提供统计信息。)
例子:
[user@host ~]$ netstat -s
Ip:
Forwarding: 2
17721 total packets received
1 with invalid addresses
0 forwarded
0 incoming packets discarded
17702 incoming packets delivered
16252 requests sent out
12 outgoing packets dropped
Icmp:
33 ICMP messages received
0 input ICMP message failed
ICMP input histogram:
destination unreachable: 33
39 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 39
IcmpMsg:
InType3: 33
OutType3: 39
Tcp:
140 active connection openings
77 passive connection openings
6 failed connection attempts
5 connection resets received
0 connections established
17554 segments received
16134 segments sent out
16 segments retransmitted
0 bad segments received
12 resets sent
Udp:
88 packets received
33 packets to unknown port received
0 packet receive errors
121 packets sent
0 receive buffer errors
0 send buffer errors
UdpLite:
TcpExt:
112 TCP sockets finished time wait in fast timer
365 delayed acks sent
1 delayed acks further delayed because of locked socket
2086 packets directly queued to recvmsg prequeue
1310 bytes directly in process context from backlog
TCPDirectCopyFromPrequeue: 1015476
9354 packet headers predicted
773 packet headers predicted and directly queued to user
1112 acknowledgments not containing data payload received
4861 predicted acknowledgments
TCPTimeouts: 24
5 connections reset due to unexpected data
2 connections aborted due to timeout
TCPDeferAcceptDrop: 12
TCPRcvCoalesce: 2246
TCPAutoCorking: 7
TCPOrigDataSent: 6211
TCPHystartTrainDetect: 4
TCPHystartTrainCwnd: 65
TCPKeepAlive: 115
IpExt:
InMcastPkts: 14
OutMcastPkts: 16
InOctets: 52113215
OutOctets: 26659850
InMcastOctets: 1882
OutMcastOctets: 1962
InNoECTPkts: 33753
答案3
贝蒙可能就是您所需要的。它将显示有关系统上每个适配器的大量信息。