官方给出的地址在这里:Monitoring VM Trafic Using sFlow(http://docs.openvswitch.org/en/latest/howto/sflow/),这里的做法跟官方做法基本一致。
openvswitch已经自带了sflow模块,不需要安装。另外我们使用了sflowtool进行监控,sflowtool的github地址在这里:sflow/sflowtool(https://github.com/sflow/sflowtool)
实验环境如下,host为ubuntu16.04 desk,其中host2为监控端
首先在host1配置一些环境变量,其实就是ovs-vsctl的命令参数,新建sflowenv文件,修改如下:
COLLECTOR_IP=192.168.1.48
COLLECTOR_PORT=6343
AGENT_IP=ens33
HEADER_BYTES=128
SAMPLING_N=64
POLLING_SECS=10
然后执行 source sflowenv命令使参数生效。前两项分别为监控端的ip和端口,第三个是代理ip,也就是host1要使用那个接口来发送sflow监控数据。
然后执行如下命令进行监控并发送数据:
ovs-vsctl -- --id=@sflow create sflow agent=${AGENT_IP} \
target="${COLLECTOR_IP}:${COLLECTOR_PORT}" header=${HEADER_BYTES} \
sampling=${SAMPLING_N} polling=${POLLING_SECS} \
-- set bridge br0 sflow=@sflow
直接执行上面命令会有问题,需要在${COLLECTOR_IP}:${COLLECTOR_PORT}的冒号之前加一个反斜杠‘\’,如下:
ovs-vsctl -- --id=@sflow create sflow agent=${AGENT_IP} \
target="${COLLECTOR_IP}\:${COLLECTOR_PORT}" header=${HEADER_BYTES} \
sampling=${SAMPLING_N} polling=${POLLING_SECS} \
-- set bridge br0 sflow=@sflow
接下来要在host2上安装sflowtool进行监控,下载,解压(unzip sflowtool.zip),安装:
./boot.sh
./configure
make
sudo make install
但是执行./boot.sh的时候,出现问题说是没有安装 aotoreconf,执行如下命令安装即可:
sudo apt-get install autoconf automake libtool
安装完成之后就可以执行sflowtool来进行监控数据收集了,sflowtool命令被放在了文件夹/usr/local/bin中。sflow监控分为count参加和sample采样,下一次将分析sflow报文。如下:
startDatagram =================================
datagramSourceIP 192.168.1.55
datagramSize 280
unixSecondsUTC 1487818805
datagramVersion 5
agentSubId 0
agent 192.168.1.54
packetSequenceNo 613
sysUpTime 1505000
samplesInPacket 2
startSample ----------------------
sampleType_tag 0:2
sampleType COUNTERSSAMPLE
sampleSequenceNo 151
sourceId 2:1000
counterBlock_tag 0:2203
user_time 7302492
system_time 6679608
memory_used 34811904
memory_max 0
files_open 0
files_max 0
connections_open 0
connections_max 0
counterBlock_tag 0:2207
skipping unknown counters_sample_element: 0:2207 len=24
endSample ----------------------
startSample ----------------------
sampleType_tag 0:2
sampleType COUNTERSSAMPLE
sampleSequenceNo 151
sourceId 0:10
counterBlock_tag 0:1004
skipping unknown counters_sample_element: 0:1004 len=12
counterBlock_tag 0:1005
ifName br0
counterBlock_tag 0:1
ifIndex 10
networkType 6
ifSpeed 100000000
ifDirection 0
ifStatus 3
ifInOctets 619119
ifInUcastPkts 3818
ifInMulticastPkts 0
ifInBroadcastPkts 4294967295
ifInDiscards 1
ifInErrors 0
ifInUnknownProtos 4294967295
ifOutOctets 137573
ifOutUcastPkts 755
ifOutMulticastPkts 4294967295
ifOutBroadcastPkts 4294967295
ifOutDiscards 0
ifOutErrors 0
ifPromiscuousMode 0
endSample ----------------------
endDatagram =================================
startDatagram =================================
datagramSourceIP 192.168.1.55
datagramSize 216
unixSecondsUTC 1487818804
datagramVersion 5
agentSubId 0
agent 192.168.1.54
packetSequenceNo 612
sysUpTime 1504000
samplesInPacket 1
startSample ----------------------
sampleType_tag 0:1
sampleType FLOWSAMPLE
sampleSequenceNo 22
sourceId 2:1000
meanSkipCount 64
samplePool 1408
dropEvents 0
inputPort 7
outputPort 11
flowBlock_tag 0:1001
extendedType SWITCH
in_vlan 0
in_priority 0
out_vlan 0
out_priority 0
flowBlock_tag 0:1
flowSampleType HEADER
headerProtocol 1
sampledPacketSize 102
strippedBytes 4
headerLen 98
headerBytes 52-54-00-D1-6D-01-52-54-00-BE-70-9B-08-00-45-00-00-54-31-F8-40-00-40-01-84-EF-C0-A8-01-38-C0-A8-01-39-08-00-5F-A2-08-45-00-39-31-50-AE-58-00-00-00-00-E4-63-0D-00-00-00-00-00-10-11-12-13-14-15-16-17-18-19-1A-1B-1C-1D-1E-1F-20-21-22-23-24-25-26-27-28-29-2A-2B-2C-2D-2E-2F-30-31-32-33-34-35-36-37
dstMAC 525400d16d01
srcMAC 525400be709b
IPSize 84
ip.tot_len 84
srcIP 192.168.1.56
dstIP 192.168.1.57
IPProtocol 1
IPTOS 0
IPTTL 64
IPID 63537
ICMPType 8
ICMPCode 0
endSample ----------------------
endDatagram =================================