[转]Network flow monitoring with Open vSwitch

With network virtualization, the software switches (such as Open vSwitch) on the servers act like the edge switches. So, to gain insights into the network flow behavior, it becomes important to have some sort of flow monitoring technique to analyze the traffic through these switches. NetFlow and sFlow are the two most widely used flow monitoring approaches. To monitor the flows, the switches need to be configured to export and send the traffic data to an analyzer (eg SolarWinds Real-Time NetFlow Analyzer and InMon sFlowTrend). The analyzer listens on a a particular port for the flow statistics data sent from the switches. In this article, I will explain how to configure an OVS to send the flow statistics to an analyzer for monitoring.

sFlow:
To begin, lets start the InMon sFlowTrend analyzer (or any other sFlow analyzer) on a host (h1). By default, sFlowTrend listens on port 6343. On the server (h2) running the open vswitch, we need to use ovs-vsctl to configure the OVS as follows:

$ COLLECTOR_IP=192.168.0.121

$ COLLECTOR_PORT=6343

$ AGENT=eth1

$ HEADER=128

$ SAMPLING=512

$ POLLING=10

COLLECTOR_IP : IP of host h1 where the analyzer is running and listening on port COLLECTOR_PORT.
AGENT : network interface on the host h2 which connects to the network on which host h1 is running.
HEADER : size (in bytes) of the packet header to be analyzed.
SAMPLING : specifies the sampling rate. Every nth packet will be sampled (with some deviation).
POLLING : polling time period in seconds.
Configure the OVS bridge 'ovsbr1' (replace with the name of the OVS bridge on your setup):

$ SFLOWUUID=`sudo ovs-vsctl -- --id=@sflow create sflow \

agent=${AGENT}  target=\"${COLLECTOR_IP}:${COLLECTOR_PORT}\" \

header=${HEADER} sampling=${SAMPLING} polling=${POLLING} \

-- set bridge virbr0 sflow=@sflow`

or

$ sudo ovs-vsctl -- --id=@sflow create sflow agent=${AGENT}  \

target=\"${COLLECTOR_IP}:${COLLECTOR_PORT}\" header=${HEADER} \

sampling=${SAMPLING} polling=${POLLING} \

-- set bridge ovsbr1 sflow=@sflow

Now, you should be able to see on the sFlow analyzer the statistics for the traffic going through this OVS bridge.
To stop the switch from sending these statistics and remove this configuration, do:

$ sudo ovs-vsctl remove bridge ovsbr1 sflow $SFLOWUUID

or to remove all the sFlow configurations from the bridge:

$ sudo ovs-vsctl -- clear Bridge ovsbr1 sflow

You can also see the list of sFlow configurations using:

$ sudo ovs-vsctl list sflow

NetFlow:
Similarly, start a NetFlow collector on a host (h1) and configure the OVS bridge on h2 as follows:

$ COLLECTOR_IP=192.168.0.121

$ COLLECTOR_PORT=6343

$ TIMEOUT=10

$ sudo ovs-vsctl -- set Bridge ovsbr1 netflow=@nf --   --id=@nf  \

create   NetFlow   targets=\"${COLLECTOR_IP}:${COLLECTOR_PORT}\" \

active-timeout=${TIMEOUT}

Verify that you are getting the NetFlow statistics on the analyzer. To deconfigure NetFlow on ovsbr1, do:

$ sudo ovs-vsctl clear Bridge ovsbr1 netflow

You can also change the timeout once the NetFlow has been configured by using:

$ sudo ovs-vsctl set NetFlow ovsbr1 active_timeout=20

Cheers!

Credits:
1. ovs-vsctl documentation
2. Open vSwitch config-cookbook

posted @   popsuper1982  阅读(820)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
点击右上角即可分享
微信分享提示