在此发行版中引入了以下两个新命令,用于观察服务器上各种类型的网络通信流量:ipstat 和 tcpstat。
ipstat 命令用于根据命令语法中指定的所选输出模式和排序顺序收集并报告有关服务器上 IP 通信流量的统计信息。使用此命令可以观察 IP 层的网络通信流量(按源、目标、高层协议和接口进行聚合)。当您希望观察一个服务器与其他服务器之间的通信量时,使用此命令。
tcpstat 命令用于根据命令语法中指定的所选输出模式和排序顺序收集并报告有关服务器上 TCP 和 UDP 通信流量的统计信息。使用此命令可以观察传输层的网络通信流量(专门用于 TCP 和 UDP)。除源和目标的 IP 地址以外,您还可以观察源和目标的 TCP 或 UDP 端口、发送或接收通信流量的进程的 PID,以及运行该进程的区域的名称。
可通过下面一些方法使用 tcpstat 命令:
标识服务器上 TCP 和 UDP 通信流量的最大源。
检查特定进程生成的通信流量。
检查从特定区域生成的通信流量。
确定哪个进程绑定到本地端口。
要使用 ipstat 和 tcpstat 命令,需要下面某种权限:
承担 root 角色
被显式指定 dtrace_kernel 权限
被指定 "Network Management"(网络管理)或"Network Observability"(网络观察)权限配置文件
以下示例演示了可使用这两个命令观察网络通信流量的各种方法。有关详细信息,请参见 tcpstat(1M) 和 ipstat(1M) 手册页。
以下示例显示使用 –c 选项运行时 ipstat 命令的输出。使用 –c 选项可以在以前的报告之后打印更新的报告,而不覆盖以前的报告。此示例中的数字 3 指定数据的显示时间间隔,与以 ipstat 3 形式调用此命令一样。
# ipstat -c 3 SOURCE DEST PROTO INT BYTES zucchini antares TCP net0 72.0 zucchini antares SCTP net0 64.0 antares zucchini SCTP net0 56.0 amadeus.foo.example.com 10.6.54.255 UDP net0 40.0 antares zucchini TCP net0 40.0 zucchini antares UDP net0 16.0 antares zucchini UDP net0 16.0 Total: bytes in: 192.0 bytes out: 112.0
作为对比,以下示例显示与 –c 选项一起使用时 tcpstat 命令的输出:
# tcpstat -c 3 ZONE PID PROTO SADDR SPORT DADDR DPORT BYTES global 100680 UDP antares 62763 agamemnon 1023 76.0 global 100680 UDP antares 775 agamemnon 1023 38.0 global 100680 UDP antares 776 agamemnon 1023 37.0 global 100680 UDP agamemnon 1023 antares 62763 26.0 global 104289 UDP zucchini 48655 antares 6767 16.0 global 104289 UDP clytemnestra 51823 antares 6767 16.0 global 104289 UDP antares 6767 zucchini 48655 16.0 global 104289 UDP antares 6767 clytemnestra 51823 16.0 global 100680 UDP agamemnon 1023 antares 776 13.0 global 100680 UDP agamemnon 1023 antares 775 13.0 global 104288 TCP zucchini 33547 antares 6868 8.0 global 104288 TCP clytemnestra 49601 antares 6868 8.0 global 104288 TCP antares 6868 zucchini 33547 8.0 global 104288 TCP antares 6868 clytemnestra 49601 8.0 Total: bytes in: 101.0 bytes out: 200.0
下面的其他一些示例演示了可使用 ipstat 和 tcpstat 命令观察网络上的通信流量的其他方法。
示例 1-14 使用 ipstat 命令观察最活跃的五个 IP 通信流以下示例报告最活跃的五个 IP 通信流。–l nlines 选项指定每个报表要输出的数据行数。
# ipstat -l 5 SOURCE DEST PROTO IFNAME BYTES charybdis.foo.example.com achilles.exampl UDP net0 6.6K eratosthenes.example.com aeneas.example.c TCP tun0 6.1K achilles.exampl charybdis.foo.example.com UDP net0 964.0 aeneas.example.c eratosthenes.example.com TCP tun0 563.0 odysseus.example. 255.255.255.255 UDP net0 66.0 Total: bytes in: 12.6K bytes out: 2.2K示例 1-15 使用 ipstat 命令显示时间戳
以下示例报告首要的 IP 通信流量并显示标准日期格式 (–d d) 的时间戳。可以指定以秒为单位或以 Unix 时间 (–d u) 形式打印时间戳。时间间隔设置为 10 秒。
# ipstat -d d -c 10 Monday, March 26, 2012 08:34:07 PM EDT SOURCE DEST PROTO IFNAME BYTES charybdis.foo.example.com achilles.exampl UDP net0 15.1K eratosthenes.example.com aeneas.example.c TCP tun0 13.9K achilles.exampl charybdis.foo.example.com UDP net0 2.4K aeneas.example.c eratosthenes.example.com TCP tun0 1.5K odysseus.example. 255.255.255.255 UDP net0 66.0 cassiopeia.foo.example.com aeneas.example.c TCP tun0 29.0 aeneas.example.c cassiopeia.foo.example.com TCP tun0 20.0 Total: bytes in: 29.1K bytes out: 3.8K示例 1-16 使用 tcpstat 命令观察最活跃的五个通信流
以下示例报告服务器的最活跃的五个 TCP 通信流:
# tcpstat -l 5 ZONE PID PROTO SADDR SPORT DADDR DPORT BYTES global 28919 TCP achilles.exampl 65398 aristotle.exampl 443 33.0 zone1 6940 TCP ajax.example.com 6868 achilles.exampl 61318 8.0 zone1 6940 TCP achilles.exampl 61318 ajax.example.com 6868 8.0 global 8350 TCP ajax.example.com 6868 achilles.exampl 61318 8.0 global 8350 TCP achilles.exampl 61318 ajax.example.com 6868 8.0 Total: bytes in: 16.0 bytes out: 49.0示例 1-17 使用 tcpstat 命令显示时间戳信息
在以下示例中,tcpstat 命令用于以标准日期格式显示服务器上 TCP 网络通信流量的时间戳信息:
# tcpstat -d d -c 10 Saturday, March 31, 2012 07:48:05 AM EDT ZONE PID PROTO SADDR SPORT DADDR DPORT BYTES global 2372 TCP penelope.example 58094 polyphemus.examp 80 37.0 zone1 6940 TCP ajax.example.com 6868 achilles.exampl 61318 8.0 zone1 6940 TCP achilles.exampl 61318 ajax.example.com 6868 8.0 global 8350 TCP ajax.example.com 6868 achilles.exampl 61318 8.0 global 8350 TCP achilles.exampl 61318 ajax.example.com 6868 8.0 Total: bytes in: 16.0 bytes out: 53.0