Traffic sampling is a critical feature for network monitoring, analysis, and troubleshooting. On Juniper devices, the sampling feature allows you to capture a portion of the traffic flowing through the router and export it to flow collectors for analysis. This enables network administrators to gain visibility into traffic patterns, detect anomalies, and plan network capacity without the overhead of capturing all traffic.
This guide covers how to configure traffic sampling on Juniper devices using jflow (Juniper's implementation of netflow/IPFIX).
Components of Traffic Sampling
Juniper's traffic sampling configuration consists of several key components:
Groups Configuration: Defines reusable configuration blocks
services {
flow-monitoring {
version9 { # Use NetFlow v9 format
template ipv4 { # Template for IPv4 flows
flow-active-timeout 10; # Export active flows every 10 seconds
flow-inactive-timeout 10; # Export inactive flows after 10 seconds
template-refresh-rate {
packets 30; # Resend template every 30 packets
seconds 30; # or every 30 seconds
}
option-refresh-rate {
packets 30;
seconds 30;
}
ipv4-template; # Use standard IPv4 template
}
template ipv6 { # Template for IPv6 flows
flow-active-timeout 10;
flow-inactive-timeout 10;
template-refresh-rate {
packets 30;
seconds 30;
}
option-refresh-rate {
packets 30;
seconds 30;
}
ipv6-template; # Use standard IPv6 template
}
}
}
}
forwarding-options {
sampling {
instance {
sample-ins { # Name of sampling instance
input {
rate 2048; # Sample 1 packet out of 2048
max-packets-per-second 65535; # Maximum packets to sample per second
}
family inet { # IPv4 configuration
output {
flow-server 192.168.88.101 { # Flow collector IP address
port 2055; # NetFlow collector port
autonomous-system-type origin; # AS path origin
source-address 192.168.88.100; # Source IP for flow packets
version9 {
template {
ipv4; # Use IPv4 template
}
}
}
inline-jflow {
source-address 192.168.88.100; # Source IP for inline jflow
}
}
}
family inet6 { # IPv6 configuration
output {
flow-server 192.168.88.101 {
port 2055;
autonomous-system-type origin;
source-address 192.168.88.100;
version9 {
template {
ipv6; # Use IPv6 template
}
}
}
inline-jflow {
source-address 192.168.88.100;
}
}
}
}
}
}
}
interfaces {
ae0 {
unit 10 {
apply-groups sampling; # Apply the "sampling" group to this interface
vlan-id 10;
family inet {
address 192.0.2.127/24;
}
}
}
}
show services accounting flow inline-jflow # Show inline jflow statistics
show services accounting errors inline-jflow # Show any inline jflow errors
show services accounting status inline-jflow # Show inline jflow status
show services accounting usage # Show accounting usage statistics
show forwarding-options sampling instance sample-ins # Show sampling instance details