Configuring sFlow

Information About sFlow

Sampled flow (sFlow) allows you to monitor real-time traffic in data networks containing switches and routers. It uses the sampling mechanism in the sFlow agent software on switches to monitor traffic and to forward the sample data to the central data collector.

The core sFlow agent workflow goes as follows:

  1. Periodic polling for collecting counter sample information from the interfaces where it is enabled.

  2. Processing the packets received for flow sampling.

  3. Composing the sFlow datagram and exporting it.

sFlow Agent

The sFlow agent periodically samples or polls the interface counters that are associated with a data source of the sampled packets. The data source can be an Ethernet interface or a range of Ethernet interfaces.

When you enable sFlow sampling, based on the sampling rate and the hardware internal random number, the ingress packets and egress packets are sent to the CPU as an sFlow-sampled packet. The sFlow agent processes the sampled packets and sends an sFlow datagram to the sFlow analyzer. In addition to the original sampled packet, an sFlow datagram includes information about the ingress port, the egress port, and the original packet length. An sFlow datagram can have multiple sFlow samples.

Prerequisites for sFlow

sFlow has the following prerequisites:

  • Ensure that the collector destination is reachable.

  • IP Routing must be enabled on the device.

Guidelines and Limitations

sFlow has the following guidelines:

  • When you enable sFlow for an interface, you can do it for ingress, egress, or in both directions.

  • You should configure the sampling rate based on the sFlow configuration and traffic in the system.

sFlow has the following limitations:

  • sFlow is supported only on physical interface.

  • The switch supports two sFlow collectors.

  • sFlow is not supported when the device boots up in stack mode.

Default Settings for sFlow

The following table lists the default settings for sFlow parameters.

Table 1. Default sFlow Parameters

Parameters

Default

sFlow sampling rate

2048

sFlow sampling size

116

sFlow counter poll interval

10

sFlow maximum datagram size

1024

sFlow collector port

6343

How to Configure sFlow

Configuring sFlow Agent

To enable sFlow agent, you must configure a valid unicast IP address on the interface.

Procedure

  Command or Action Purpose
Step 1

configure terminal

Example:


Switch# configure terminal

Enters global configuration mode.

Step 2

[no] sflow agent {ip ipv4 address | ipv6 ipv6 address}

Example:


Switch(config)# sflow agent ip 10.1.1.1

Configures IP address on the interface and enables sFlow Agent. Use the no form of this command to disable sFlow Agent.

In case of IPv6 address, it must be a global unicast address.

Step 3

end

Example:


Switch(config)# end

Returns to privileged EXEC mode.

Step 4

show sflow

Example:


Switch# show sflow

(Optional) Displays the global sflow configuration.

Step 5

copy running-config startup-config

Example:


Switch# copy running-config startup-config 

(Optional) Saves your entries in the configuration file.

Configuring sFlow Collector

Procedure

  Command or Action Purpose
Step 1

configure terminal

Example:


Switch# configure terminal

Enters global configuration mode.

Step 2

sflow collector {id collector-id } {ip ipv4 address | ipv6 ipv6 address} [port <port>] [datagram-size <max-datagram-size bytes>]

Example:


Switch(config)# sflow collector id 1 ip 10.1.1.2 port 6343 datagram-size 1024 

Configures the sFlow collector. The IP address must be specified.

  • collector-id —Must be in the value range of <1-2>.

  • port —Port value must be in the range of <1-65535>; default is 6343.

  • max-datagram-size bytes —Sets the value of maximum datagram size in bytes <1024 - 9000>; default is 1024.

Step 3

[no] sflow collector {id collector-id }

Example:


Switch(config)# no sflow collector id 1 

Deletes the configurations for sFlow collector.

Step 4

end

Example:


Switch(config)# end

Returns to privileged EXEC mode.

Step 5

show sflow

Example:


Switch# show sflow

(Optional) Displays the global sflow configuration.

Step 6

copy running-config startup-config

Example:


Switch# copy running-config startup-config 

(Optional) Saves your entries in the configuration file.

Configuring Flow Sampling

Procedure

  Command or Action Purpose
Step 1

configure terminal

Example:


Switch# configure terminal

Enters global configuration mode.

Step 2

interface interface-id

Example:


Switch(config)# interface gigabitethernet1/0/2 

Enters interface configuration mode.

Step 3

sflow flow-sampling {input |output } id collector-id [rate <rate>] [hdr-size <max-header-size bytes>]

Example:


Switch(config-if)# sflow flow-sampling input id 1 rate 256 hdr-size 200 

Specifies the collector-id to which the packet samples from that interface needs to be sent.

  • collector-id —Must be in the value range of <1-2>.

  • rate —Sampling rate in the range of <256-1073741823>; default is 2048.

  • max-header-size bytes —Maximum header size to be copied in bytes in the range <18-512>; default is 116.

Step 4

no sflow flow-sampling {input |output }

Example:


Switch(config-if)# no sflow flow-sampling input 

Deletes configurations for flow sampling on the interface.

Step 5

end

Example:


Switch(config)# end

Returns to privileged EXEC mode.

Step 6

show sflow interface

Example:


Switch# show sflow interface gigabitethernet1/0/2

Displays the sflow configuration on all the interfaces where flow packet sampling is enabled.

Step 7

copy running-config startup-config

Example:


Switch# copy running-config startup-config 

(Optional) Saves your entries in the configuration file.

Configuring Counter Sampling

Procedure

  Command or Action Purpose
Step 1

configure terminal

Example:


Switch# configure terminal

Enters global configuration mode.

Step 2

interface interface-id

Example:


Switch(config)# interface gigabitethernet1/0/2 

Enters interface configuration mode.

Step 3

sflow counter-sampling id collector-id [interval <interval>]

Example:


Switch(config-if)# sflow counter-sampling id 1 interval 15 

Specifies the collector-id to which the counter samples from that interface must be sent.

  • collector-id —Must be in the value range of <1-2>.

  • interval —Counter poll interval in seconds in the range of <2-86400>; default is 10 seconds.

Step 4

no sflow counter-sampling

Example:


Switch(config-if)# no sflow counter-sampling 

Disables counter sampling.

Step 5

end

Example:


Switch(config)# end

Returns to privileged EXEC mode.

Step 6

show sflow interface

Example:


Switch# show sflow interface gigabitethernet1/0/2

Displays the sflow configuration on all the interfaces where counter sampling is enabled.

Step 7

copy running-config startup-config

Example:


Switch# copy running-config startup-config 

(Optional) Saves your entries in the configuration file.

Verifying sFlow Configuration

Use these commands to display and verify the sFlow configuration.

Table 2. sFlow Show Commands

Command

Purpose

show sflow

Displays global sFlow configuration for sFlow agent and sFlow collector.

show sflow interface

Displays sFlow configuration on all interfaces where either packet sampling or counter sampling is enabled.

show sflow interface <interface name>

Displays the configurations specifically on a given interface.

show platform sflow enables

Displays the global sFlow status at the hardware level.

Monitoring and Clearing sFlow Statistics

Table 3. Monitoring and Clearing sFlow Statistics

Command

Description

show sflow statistics

Displays sFlow statistics.

show sflow statistics interface <interface name>

Displays interface level statistics for the given interface such number of packet samples received in ingress and egress.

clear sflow statistics

Clears sFlow statistics.

clear sflow statistics interface <interface name>

Clears interface level sFlow statistics.

Configuration Examples for sFlow

This example shows how to configure sFlow at the global level:

Switch#configure terminal
Switch(config)#sflow agent ip 10.1.1.1
Switch(config)#sflow collector id 1 ip 10.1.1.2 port 6343 datagram-size 1024
Switch(config)#sflow collector id 2 ip 10.1.1.3 port 6343 datagram-size 1024
Switch#

This example displays global sFlow configuration for sFlow agent and sFlow collector:

Switch#show sflow
Switch#show sflow
Agent:
------
IP : 10.1.1.1
Collector:
----------
Max number of collectors : 2
Id | Collector IP | Port | Max Datagram size
--------------------------------------------------------------
1 | 10.1.1.2 | 6343 | 1024
2 | 10.1.1.3 | 6343 | 1024
Switch#

This example shows how to configure sFlow at the interface level:

Switch#configure terminal
Switch(config)#interface gigabitethernet1/0/15
Switch(config-if)#sflow flow-sampling input id 1 rate 256 hdr-size 200
Switch(config-if)#sflow flow-sampling output id 1 rate 256 hdr-size 200
Switch(config-if)#sflow counter-sampling id 1 interval 15

This example shows the output of sFlow configuration on the interface where either packet sampling or counter sampling is enabled:

Switch#show sflow interface
In: Input direction, Out: Output direction, '0' indicates No configuration
---------------------------------------------------------------------------------
| Flow sampling |
|-------------------------------------------------|
| Sampling Rate | HdrBytes | Coll Id | Counter Sampling
|----------------------------|----------|---------|--------------------
Interface | In Out | In Out | In Out | Interval | Coll Id
---------------------------------------------------------------------------------
Gi1/0/15 | 1/256, 1/256 | 200, 200 | 1, 1 | 15 Sec | 1

Feature History and Information for sFlow

Release Feature Information

Cisco IOS Release 15.2(7)E

This feature was introduced.