Related Documentation
- M, PTX, T Series
- Traffic Sampling, Forwarding, and Monitoring Overview
- M, MX, T Series
- Configuring Sampling Instances
Configuring Traffic Sampling
Traffic sampling enables you to copy traffic to a Physical Interface Card (PIC) that performs flow accounting while the router forwards the packet to its original destination. You can configure the router to perform sampling in either of two locations:
- On the Routing Engine, using the sampled process. To select this method, use a filter (input or output) with a matching term that contains the then sample statement.
- On the Monitoring Services, Adaptive Services, or Multiservices PIC.
![]() | Note: Routing Engine based sampling is not supported on VPN routing and forwarding (VRF) instances. |
The following sections provide configuration instructions for traffic sampling:
Minimum Configuration for Traffic Sampling
To configure traffic sampling on a logical interface, you must perform at least the following tasks:
- Create a firewall filter to apply to the logical interfaces
being sampled by including the filter statement at the [edit firewall family family-name] hierarchy
level. In the filter then statement, you must specify the
action modifier sample and the action accept.filter filter-name {term term-name {then {sample;accept;}}}
For more information about firewall filter actions and action modifiers, see the Routing Policy Feature Guide for Routing Devices.
- Apply the filter to the interfaces on which you want to sample traffic by including the address and filter statements at the [edit interfaces interface-name unit logical-unit-number family family-name] hierarchy level:
- Enable sampling and specify a nonzero sampling rate by
including the sampling statement at the [edit forwarding-options] hierarchy level:sampling {input {rate number;run-length number;max-packets-per-second number;maximum-packet-length bytes;}}
Configuring Traffic Sampling
To configure traffic sampling on any logical interface, include the input statement at the [edit forwarding-options sampling] hierarchy level:
When you use Routing Engine-based sampling, specify the threshold traffic value by including the max-packets-per-second statement. The value is the maximum number of packets to be sampled, beyond which the sampling mechanism begins dropping packets. The range is from 0 through 65,535. A value of 0 instructs the Packet Forwarding Engine not to sample any packets. The default value is 1000.
![]() | Note: When you configure active monitoring and specify a Monitoring Services, Adaptive Services, or Multiservices PIC in the output statement, the max-packets-per-second value is ignored. |
Specify the sampling rate by setting the values for rate and run-length (see Figure 1).
Figure 1: Configure Sampling Rate

The rate statement specifies the ratio of packets to be sampled. For example, if you configure a rate of 10, x number of packets out of every 10 is sampled, where x=run-length+1. By default, the rate is 0, which means that no traffic is sampled.
The run-length statement specifies the number of matching packets to sample following the initial one-packet trigger event. By default, the run-length is 0, which means that no more traffic is sampled after the trigger event. The range is from 0 through 20. Configuring a run length greater than 0 allows you to sample packets following those already being sampled.
![]() | Note: The run-length and maximum-packet-length configuration statements are not supported on MX80 routers. |
If you do not include the input statement, sampling is disabled.
To collect the sampled packets in a file, include the file statement at the [edit forwarding-options sampling output] hierarchy level. Output file formats are discussed later in the chapter.
Disabling Traffic Sampling
To explicitly disable traffic sampling on the router, include the disable statement at the [edit forwarding-options sampling] hierarchy level:
Sampling Once
To explicitly sample a packet for active monitoring only once, include the sample-once statement at the [edit forwarding-options sampling] hierarchy level:
Setting this option avoids duplication of packets in cases where sampling is enabled at both the ingress and egress interfaces and simplifies analysis of the sampled traffic.
Configuring Traffic Sampling Output
To configure traffic sampling output, include the following statements at the [edit forwarding-options sampling family (inet | inet6 | mpls) output] hierarchy level:
To configure inline flow monitoring on MX Series routers, include the inline-jflow statement at the [edit forwarding-options sampling instance instance-name family (inet | inet6 | mpls) output] hierarchy level. Inline sampling exclusively supports a new format called IP_FIX that uses UDP as the transport protocol. When you configure inline sampling, you must include the version-ipfix statement at the [edit forwarding-options sampling instance instance-name family (inet | inet6 | mpls) output flow-server address] hierarchy level and also at the [edit services flow-monitoring] hierarchy level. For more information about configuring inline flow monitoring, see Configuring Inline Sampling.
To direct sampled traffic to a flow-monitoring interface, include the interface statement. The engine-id and engine-type statements specify the identity and type numbers of the interface; they are dynamically generated based on the Flexible PIC Concentrator (FPC), PIC, and slot numbers and the chassis type. The source-address statement specifies the traffic source.
To configure flow sampling version 9 output, you need to include the template statement at the [edit forwarding-options sampling output version9] hierarchy level. For information on cflowd, see Enabling Flow Aggregation.
The aggregate-export-interval statement is described in Configuring Discard Accounting, and the flow-active-timeout and flow-inactive-timeout statements are described in Configuring Flow Monitoring.
Traffic sampling results are automatically saved to a file in
the/var/tmp
directory. To collect
the sampled packets in a file, include the file statement
at the [edit forwarding-options sampling family inet output] hierarchy level:
Traffic Sampling Output Format
Traffic sampling output is saved to an ASCII text file. The
following is an example of the traffic sampling output that is saved
to a file in the/var/tmp
directory.
Each line in the output file contains information for one sampled
packet. You can optionally display a timestamp for each line.
The column headers are repeated after each group of 1000 packets.
# Apr 7 15:48:50 Time Dest Src Dest Src Proto TOS Pkt Intf IP TCP addr addr port port len num frag flags Apr 7 15:48:54 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:55 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:56 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:57 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0 Apr 7 15:48:58 192.168.9.194 192.168.9.195 0 0 1 0x0 84 8 0x0 0x0
To set the timestamp option for the file my-sample, enter the following:
Whenever you toggle the timestamp option, a new header is included in the file. If you set the stamp option, the Time field is displayed.
# Apr 7 15:48:50 # Time Dest Src Dest Src Proto TOS Pkt Intf IP TCP # addr addr port port len num frag flags # Feb 1 20:31:21 # Dest Src Dest Src Proto TOS Pkt Intf IP TCP # addr addr port port len num frag flags
Tracing Traffic Sampling Operations
Tracing operations track all traffic sampling operations and
record them in a log file in the/var/log
directory. By default, this file is named /var/log/sampled
. The default file size is 128K, and 10 files are created before
the first one gets overwritten.
To trace traffic sampling operations, include the traceoptions statement at the [edit forwarding-options sampling] hierarchy level:
Traffic Sampling Examples
The following sections provide examples of configuring traffic sampling:
- Example: Sampling a Single SONET/SDH Interface
- Example: Sampling All Traffic from a Single IP Address
- Example: Sampling All FTP Traffic
Example: Sampling a Single SONET/SDH Interface
The following configuration gathers statistical sampling information from a small percentage of all traffic on a single SONET/SDH interface and collects it in a file named sonet-samples.txt.
Create the filter:
Apply the filter to the SONET/SDH interface:
Finally, configure traffic sampling:
Example: Sampling All Traffic from a Single IP Address
The following configuration gathers statistical information about every packet entering the router on a specific Gigabit Ethernet port originating from a single source IP address of 172.16.92.31, and collects it in a file named samples-172-16-92-31.txt.
Create the filter:
Apply the filter to the Gigabit Ethernet interface:
Finally, gather statistics on all the candidate samples; in this case, gather all statistics:
Example: Sampling All FTP Traffic
The following configuration gathers statistical information about a moderate percentage of packets using the FTP data transfer protocol in the output path of a specific T3 interface, and collects the information in a file named t3-ftp-traffic.txt.
Create a filter:
Apply the filter to the T3 interface:
Finally, gather statistics on 10 percent of the candidate samples:
Related Documentation
- M, PTX, T Series
- Traffic Sampling, Forwarding, and Monitoring Overview
- M, MX, T Series
- Configuring Sampling Instances
Published: 2013-08-29
Related Documentation
- M, PTX, T Series
- Traffic Sampling, Forwarding, and Monitoring Overview
- M, MX, T Series
- Configuring Sampling Instances