使用 sFlow 监控系统统计信息和网络流量
sFlow 是一种监控协议,用于对网络数据包、应用程序操作和系统计数器进行采样。 sFlow 收集接口计数器和采样的 5 元组数据包信息,以便您可以监控网络流量以及交换机状态和性能指标。 要收集和分析此数据,您需要外部服务器; 一个 sFlow 收集器。
配置 sFlow
要配置 sFlow
- 提供 sFlow 收集器。如果您启用 sFlow,则必须至少配置一个收集器。
- 设置 sFlow 采样率。
- 设置轮询间隔。
- 提供 sFlow 代理的 IP 地址和接口。
- 配置 sFlow 监管器速率和监管器突发。
- 启用 sFlow
Cumulus Linux 提供不同的采样率配置。该值表示采样率;例如,如果您指定值 400,则 SFlow 每 400 个数据包采样一次。
采样率 | 默认值 | 描述 |
---|---|---|
speed-100m | 100 | 100Mbps 端口上的采样率。 |
speed-1g | 1000 | 1Gbps 端口上的采样率。 |
speed-10g | 10000 | 10Gbps 端口上的采样率。 |
speed-40g | 40000 | 40Gbps 端口上的采样率。 |
speed-50g | 50000 | 50Gbps 端口上的采样率。 |
speed-100g | 100000 | 100Gbps 端口上的采样率。 |
speed-200g | 200000 | 200Gbps 端口上的采样率。 |
speed-400g | 400000 | 400Gbps 端口上的采样率。 |
speed-800g | 800000 | 800Gbps 端口上的采样率。 |
某些收集器要求每个源在不同的端口上传输,而其他收集器仅在一个端口上侦听。有关更多信息,请参阅收集器的文档。
配置指定的收集器
指定指定收集器的 IP 地址、UDP 端口号和接口。端口号和接口是可选的;如果您未指定端口号,则 Cumulus Linux 使用默认端口 6343。
以下示例配置 sFlow 以将数据发送到端口 6343 上的收集器 192.0.2.100 和 eth0 上的收集器 192.0.2.200
cumulus@switch:~$ nv set system sflow collector 192.0.2.100 port 6344
cumulus@switch:~$ nv set system sflow collector 192.0.2.200 interface eth0
cumulus@switch:~$ nv config apply
如果您不想使用默认速率,请配置数据包数量的 sFlow 采样率和轮询间隔(以秒为单位)。
以下示例每 20 秒轮询一次计数器,并对 40G 接口的每 40000 个数据包采样一个
cumulus@switch:~$ nv set system sflow sampling-rate speed-40g 40000
cumulus@switch:~$ nv set system sflow poll-interval 20
cumulus@switch:~$ nv config apply
编辑 /etc/hsflowd.conf
文件以设置收集器、采样率和轮询间隔(以秒为单位),然后使用 sudo systemctl start hsflowd
命令重新启动 hsflowd
服务。
以下示例每 20 秒轮询一次计数器,对 40G 接口的每 40000 个数据包采样 1 个,并将此信息发送到端口 6343 上 192.0.2.100 的收集器和接口 eth0 上 192.0.2.200 的另一个收集器。
cumulus@switch:~$ sudo nano /etc/hsflowd.conf
sflow {
# ====== Sampling/Polling/Collectors ======
# EITHER: automatic (DNS SRV+TXT from _sflow._udp):
# DNS-SD { }
# OR: manual:
# Counter Polling:
polling = 20
# default sampling N:
# sampling = 400
# sampling N on interfaces with ifSpeed:
sampling.100M = 100
sampling.1G = 1000
sampling.10G = 10000
sampling.40G = 40000
# sampling N for apache, nginx:
# sampling.http = 50
# sampling N for application (requires json):
# sampling.app.myapp = 100
# collectors:
collector { ip=192.0.2.100 udpport=6344 }
collector { ip=192.0.2.200 interface=eth0 }
}
cumulus@switch:~$ sudo systemctl start hsflowd
配置 SFlow 代理
提供 sFlow 代理的 IP 地址或前缀,或接口。
以下示例将 sFlow 代理前缀配置为 10.0.0.0/8
cumulus@switch:~$ nv set system sflow agent ip 10.0.0.0/8
cumulus@switch:~$ nv config apply
以下示例将 sFlow 代理接口配置为 eth0
cumulus@switch:~$ nv set system sflow agent interface eth0
cumulus@switch:~$ nv config apply
要为 sFlow 代理提供 IP 地址或前缀,请编辑 /etc/hsflowd.conf
文件以设置 agent.CIDR
参数,然后使用 sudo systemctl start hsflowd
命令重新启动 hsflowd
服务。
cumulus@switch:~$ sudo nano /etc/hsflowd.conf
...
sflow {
agent.CIDR = 10.0.0.0/8
}
cumulus@switch:~$ sudo systemctl start hsflowd
要为 sFlow 代理提供接口,请编辑 /etc/hsflowd.conf
文件以设置 agent
参数,然后使用 sudo systemctl start hsflowd
命令重新启动 hsflowd
服务。
cumulus@switch:~$ sudo nano /etc/hsflowd.conf
...
sflow {
agent = eth0
}
cumulus@switch:~$ sudo systemctl start hsflowd
配置 sFlow 监管器速率和突发大小
您可以限制交换机每秒发送的 sFlow 样本数和每秒样本突发大小。
默认的 sFlow 样本数和默认样本大小为 16384。您可以指定介于 0 和 16384 之间的值。
以下示例将 sFlow 样本数设置为 800,样本大小设置为 900
cumulus@switch:~$ nv set system sflow policer rate 8000
cumulus@switch:~$ nv set system sflow policer burst 9000
cumulus@switch:~$ nv config apply
编辑 /etc/cumulus/datapath/traffic.conf
文件以更改 sflow.rate
和 sflow.burst
参数,然后使用 sudo systemctl reload switchd.service
命令重新加载 switchd
。
cumulus@switch:~$ sudo nano /etc/cumulus/datapath/traffic.conf
# Set sflow/sample ingress cpu packet rate and burst in packets/sec
# Values: {0..16384}
sflow.rate = 8000
sflow.burst = 9000
cumulus@switch:~$ sudo systemctl reload switchd.service
启用 sFlow
要启用 sFlow
cumulus@switch:~$ nv set system sflow state enabled
cumulus@switch:~$ nv config apply
要禁用 sFlow,请运行 nv set system sflow state disabled
命令。
默认情况下,hsflowd
服务处于禁用状态,并且在交换机启动时不会自动启动。
要启用和启动 hsflowd
服务
cumulus@switch:~$ sudo systemctl enable hsflowd
cumulus@switch:~$ sudo systemctl start hsflowd
要禁用 hsflowd
服务
cumulus@switch:~$ sudo systemctl stop hsflowd
cumulus@switch:~$ sudo systemctl disable hsflowd
接口配置
默认情况下,sFlow 在操作上处于 UP 状态的接口上启用。要在接口上禁用 sFlow
cumulus@switch:~$ nv set interface swp1 sflow state disabled
cumulus@switch:~$ nv config apply
要在接口上启用 sFlow,请运行 nv set interface <interface> sflow state enabled
命令。
默认情况下,sFlow 在操作上处于 UP 状态的接口上启用。要在特定接口上禁用 sFlow,请编辑 /etc/cumulus/switchd.conf
文件并将 interface.<interface>.sflow.enable
参数设置为 FALSE
cumulus@switch:~$ sudo nano /etc/cumulus/switchd.conf
interface.swp1.sflow.enable = FALSE
要在接口上启用 sFlow,请将 interface.<interface>.sflow.enable
参数设置为 TRUE
。
要在接口上配置 sFlow 采样率。
cumulus@switch:~$ nv set interface swp1 sflow sample-rate 100000
cumulus@switch:~$ nv config apply
编辑 /etc/cumulus/switchd.conf
文件并设置 interface.<interface-id>.sflow.sample_rate.ingress
参数
cumulus@switch:~$ sudo nano /etc/cumulus/switchd.conf
interface.swp1.sflow.sample_rate.ingress = 100000
监控丢弃的数据包
您可以配置 sFlow 以监控硬件中丢弃的数据包。
cumulus@switch:~$ nv set system sflow dropmon hw
cumulus@switch:~$ nv config apply
编辑 /etc/hsflowd.conf
文件以将 dropmon { group=1 start=off limit=1000 }
行中的 start
更改为 on
。
cumulus@switch:~$ sudo nano /etc/hsflowd.conf
dropmon { group=1 start=on limit=1000 }
使用 sudo systemctl start hsflowd
命令重新启动 hsflowd
服务。
配置 sFlow 可视化工具
有关配置各种 sFlow 可视化工具的信息,请阅读这篇知识库文章。
显示 sFlow 配置
要显示交换机上的所有 sFlow 配置
cumulus@switch:~$ nv show system sflow
operational applied
------------- ----------- -----------
poll-interval 20
state enabled
[collector] 192.0.2.100
[collector] 192.0.2.200
sampling-rate
default 400
speed-100m 100
speed-1g 1000
speed-10g 10000
speed-25g 25000
speed-40g 40000
speed-50g 50000
speed-100g 100000
speed-200g 200000
speed-400g 400000
speed-800g 800000
agent
ip 10.0.0.0/8
interface eth0
policer
rate 8000
burst 9000
[dropmon] sw
要显示 sFlow 收集器配置
cumulus@switch:~$ nv show system sflow collector
Ip Port
---------------------------------
192.0.2.100 6343
192.0.2.200 6344
要显示 sFlow 采样率配置
cumulus@switch:~$ nv show system sflow sampling-rate
applied
---------- -------
default 400
speed-100m 100
speed-1g 1000
speed-10g 10000
speed-25g 25000
speed-40g 40000
speed-50g 50000
speed-100g 100000
speed-200g 200000
speed-400g 400000
speed-800g 800000
要显示 sFlow 代理配置
cumulus@switch:~$ nv show system sflow agent
operational applied
--------- ----------- ----------
ip 10.0.0.0/8
interface eth0
要显示交换机每秒发送的样本数和每秒样本突发大小
cumulus@switch:~$ nv show system sflow policer
----------------------
applied
----- -------
rate 8000
burst 9000
要显示特定接口上的 sFlow 配置
cumulus@switch:~$ nv show interface swp1 sflow
----------------------
operational applied
----------- ----------- -------
sample-rate 0 100000
state disabled enabled
注意事项
Cumulus Linux 不支持 sFlow 出口采样。