콘텐츠로 이동

sFlow Cheat Sheet

Overview

sFlow (sampled Flow) is an industry-standard network monitoring technology defined in RFC 3176. Unlike NetFlow which tracks every flow, sFlow uses statistical sampling to capture a representative subset of traffic, making it highly scalable for monitoring high-speed networks (10G, 40G, 100G+) with minimal impact on network device performance. sFlow operates by randomly sampling 1-in-N packets at the switch/router ASIC level and periodically polling interface counters, then exporting this data as UDP datagrams to a central collector.

sFlow is supported by over 30 network equipment vendors including Arista, Juniper, HP/Aruba, Dell, Mellanox, Cumulus, and many others, making it the most widely supported flow monitoring technology. It provides real-time visibility with sampling rates that can be adjusted to balance detail versus overhead. sFlow samples include full packet headers (up to 128 bytes by default), enabling deep analysis of protocols, applications, and security events. The sFlow ecosystem includes open-source collectors (sflowtool, sFlow-RT, pmacct), commercial platforms (InMon Traffic Sentinel, Kentik), and integration with tools like ntopng, Grafana, and Elasticsearch.

Installation (Collector Tools)

sflowtool

# Ubuntu/Debian
sudo apt update
sudo apt install sflowtool

# From source
git clone https://github.com/sflow/sflowtool.git
cd sflowtool
./boot.sh
./configure
make
sudo make install

# Verify
sflowtool -h

sFlow-RT (Real-Time Analytics)

# Download sFlow-RT
wget https://inmon.com/products/sFlow-RT/sflow-rt.tar.gz
tar xzf sflow-rt.tar.gz
cd sflow-rt

# Start sFlow-RT
./start.sh

# Or with Docker
docker run -d \
  --name sflow-rt \
  -p 6343:6343/udp \
  -p 8008:8008 \
  sflow/sflow-rt

Host sFlow Agent (hsflowd)

# Ubuntu/Debian
sudo apt install hsflowd

# CentOS/RHEL
sudo yum install hsflowd

# Configure and start
sudo systemctl start hsflowd
sudo systemctl enable hsflowd

Switch/Router Configuration

Arista EOS

! Configure sFlow
sflow run
sflow source-interface Loopback0
sflow destination 10.0.0.100

! Set sampling rate (1 in 2048)
sflow sample 2048

! Enable on specific interfaces
interface Ethernet1
 sflow enable

! Per-interface sampling rate
interface Ethernet1
 sflow sampling 4096

! Verify
show sflow
show sflow interfaces

Juniper JunOS

! Configure sFlow
set protocols sflow collector 10.0.0.100 udp-port 6343
set protocols sflow polling-interval 20
set protocols sflow sample-rate ingress 2048
set protocols sflow source-ip 10.0.0.1

! Enable on interfaces
set protocols sflow interfaces ge-0/0/0
set protocols sflow interfaces ge-0/0/1

! Verify
show sflow
show sflow collector
show sflow interface

Cumulus Linux

# /etc/cumulus/hsflowd.conf
sflow {
  agent = eth0
  polling = 20
  sampling = 2048
  collector {
    ip = 10.0.0.100
    udpport = 6343
  }
}

# Restart service
sudo systemctl restart hsflowd

HP/Aruba

! Configure sFlow
sflow 1 destination 10.0.0.100 6343
sflow 1 polling all 20
sflow 1 sampling all 2048

! Enable sFlow
sflow 1 enable

! Verify
show sflow 1
show sflow 1 destination

Open vSwitch

# Configure sFlow on OVS
sudo ovs-vsctl -- --id=@s create sflow \
  agent=eth0 \
  target=\"10.0.0.100:6343\" \
  sampling=2048 \
  polling=20 \
  -- set bridge br0 sflow=@s

# Verify
sudo ovs-vsctl list sflow

# Remove sFlow
sudo ovs-vsctl remove bridge br0 sflow $(sudo ovs-vsctl get bridge br0 sflow)

sflowtool Usage

# Receive and display sFlow data
sflowtool -p 6343

# Output in line format
sflowtool -p 6343 -l

# Output as NetFlow v5 (convert sFlow to NetFlow)
sflowtool -p 6343 -c 127.0.0.1 -d 2055

# Output as pcap
sflowtool -p 6343 -r > output.pcap

# Output as tcpdump-like format
sflowtool -p 6343 -t

# Write to pcap file with rotation
sflowtool -p 6343 -r -f /var/log/sflow/capture

# Output specific fields
sflowtool -p 6343 -l | awk '{print $1, $2, $9, $10, $11}'

# Pipe to tcpdump for analysis
sflowtool -p 6343 -r | tcpdump -r - -n

# JSON output
sflowtool -p 6343 -J

sflowtool Output Fields (Line Mode)

Field PositionDescription
1Agent IP address
2Input interface index
3Output interface index
4Source MAC
5Destination MAC
6Ethernet type
7Source VLAN
8Source IP
9Destination IP
10IP protocol
11IP ToS
12Source port
13Destination port
14TCP flags
15Packet size

sFlow-RT Analytics

REST API

# Base URL: http://localhost:8008

# Get agents
curl http://localhost:8008/agents/json

# Get agent metrics
curl http://localhost:8008/metric/ALL/ifinoct/json

# Define a flow
curl -X PUT -H "Content-Type: application/json" \
  -d '{"keys":"ipsource,ipdestination","value":"bytes"}' \
  http://localhost:8008/flow/top-talkers/json

# Get flow results
curl http://localhost:8008/flow/top-talkers/json

# Define threshold alert
curl -X PUT -H "Content-Type: application/json" \
  -d '{"metric":"top-talkers","value":1000000,"byFlow":true}' \
  http://localhost:8008/threshold/high-traffic/json

# Get active thresholds
curl http://localhost:8008/threshold/json

# Get events (alerts)
curl http://localhost:8008/events/json

# Interface counters
curl http://localhost:8008/metric/ALL/ifinoct,ifoutoc/json

# Top N flows
curl "http://localhost:8008/flow/top-talkers/json?maxFlows=20"

sFlow-RT Applications

# Install sFlow-RT apps
cd sflow-rt/app

# Top Flows app
wget https://github.com/sflow-rt/top-flows/archive/master.tar.gz
tar xzf master.tar.gz

# DDoS Protect
wget https://github.com/sflow-rt/ddos-protect/archive/master.tar.gz

# Browse available apps
# http://localhost:8008/app/index.html

Host sFlow (hsflowd)

Configuration

# /etc/hsflowd.conf
sflow {
  sampling = 512
  polling = 30
  agentIP = eth0

  collector {
    ip = 10.0.0.100
    udpport = 6343
  }

  # Monitor Docker containers
  docker { }

  # Monitor KVM/libvirt VMs
  kvm { }

  # OS performance counters
  os10 { }

  # Application monitoring
  app {
    name = myapp
    sampling = 100
  }
}
# Restart after config changes
sudo systemctl restart hsflowd

# Check status
sudo systemctl status hsflowd

# View debug output
sudo hsflowd -d

Advanced Usage

Sampling Rate Selection

Network SpeedRecommended RateRationale
100 Mbps1:256Small network, high detail
1 Gbps1:1024Standard monitoring
10 Gbps1:2048Balance detail and load
40 Gbps1:4096High-speed links
100 Gbps1:8192Very high-speed monitoring

sFlow with Grafana

# Use sFlow-RT Prometheus exporter
# Start sFlow-RT with Prometheus app
cd sflow-rt
./start.sh -Dapp.prometheus=yes

# Prometheus scrape config
# prometheus.yml:
scrape_configs:
  - job_name: 'sflow-rt'
    static_configs:
      - targets: ['localhost:8008']
    metrics_path: '/prometheus/metrics'

# Create Grafana dashboards from sFlow metrics

Security Monitoring

# Detect DDoS using sFlow-RT
curl -X PUT -H "Content-Type: application/json" \
  -d '{"keys":"ipdestination","value":"frames","filter":"direction=ingress"}' \
  http://localhost:8008/flow/ddos-target/json

curl -X PUT -H "Content-Type: application/json" \
  -d '{"metric":"ddos-target","value":10000,"byFlow":true,"timeout":5}' \
  http://localhost:8008/threshold/ddos-detect/json

# Port scan detection
curl -X PUT -H "Content-Type: application/json" \
  -d '{"keys":"ipsource","value":"unique:ipdestination.udpport","filter":"tcpflags=2"}' \
  http://localhost:8008/flow/port-scan/json

Troubleshooting

IssueSolution
No sFlow data arrivingCheck UDP/6343 open, verify switch config
Inaccurate traffic totalsAdjust sampling rate, check scaling factor
Missing protocols in samplesIncrease header bytes captured (default 128)
High CPU on collectorReduce polling frequency, increase sampling
Counter data but no samplesVerify sampling is enabled on interfaces
Agent address wrongSet explicit source-ip on switch config
sFlow-RT not showing flowsCheck flow definition, verify agent connection
Docker containers not monitoredEnable Docker module in hsflowd.conf

Diagnostic Commands

# Verify sFlow packets arriving
sudo tcpdump -i eth0 -n udp port 6343 -c 10

# Decode sFlow packets
sflowtool -p 6343 | head -50

# Check sFlow-RT agents
curl http://localhost:8008/agents/json | python3 -m json.tool

# Verify hsflowd
sudo hsflowd -d    # Debug mode
journalctl -u hsflowd -f

# Count samples per second
sflowtool -p 6343 -l | pv -l > /dev/null