# phpman > man > tc-sample(8)

Packet sample action in [tc(8)](https://www.chedong.com/phpMan.php/man/tc/8/markdown)                   Linux                  Packet sample action in [tc(8)](https://www.chedong.com/phpMan.php/man/tc/8/markdown)



## NAME
       sample - packet sampling tc action

## SYNOPSIS
       **tc** ... **action** **sample** **rate** _RATE_ **group** _GROUP_ [ **trunc** _SIZE_ ] [ **index** _INDEX_ ]

       **tc** ... **action** **sample** **index** _INDEX_


## DESCRIPTION
       The **sample** action allows sampling packets matching classifier.

       The  packets  are  chosen randomly according to the **rate** parameter, and are sampled using the
       **psample** generic netlink channel. The user can also specify packet truncation  to  save  user-
       kernel  traffic.  Each  sample  includes some informative metadata about the original packet,
       which is sent using netlink attributes, alongside the original packet data.

       The user can either specify the sample action parameters  as  presented  in  the  first  form
       above, or use an existing sample action using its index, as presented in the second form.


## SAMPLED PACKETS METADATA FIELDS
       The  metadata are delivered to userspace applications using the **psample** generic netlink chan‐
       nel, where each sample includes the following netlink attributes:

       **PSAMPLE**___**ATTR**___**IIFINDEX**
              The input interface index of the packet, if there is one.

       **PSAMPLE**___**ATTR**___**OIFINDEX**
              The output interface index of the packet. This field is not relevant on  ingress  sam‐
              pling

       **PSAMPLE**___**ATTR**___**ORIGSIZE**
              The size of the original packet (before truncation)

       **PSAMPLE**___**ATTR**___**SAMPLE**___**GROUP**
              The **psample** group the packet was sent to

       **PSAMPLE**___**ATTR**___**GROUP**___**SEQ**
              A  sequence number of the sampled packet. This number is incremented with each sampled
              packet of the current **psample** group

       **PSAMPLE**___**ATTR**___**SAMPLE**___**RATE**
              The rate the packet was sampled with


## OPTIONS
       **rate** _RATE_
              The packet sample rate.  _RATE_ is the expected ratio between observed packets and  sam‐
              pled  packets.  For example, _RATE_ of 100 will lead to an average of one sampled packet
              out of every 100 observed.

       **trunc** _SIZE_
              Upon set, defines the maximum size of the sampled packets, and  causes  truncation  if
              needed

       **group** _GROUP_
              The  **psample**  group the packet will be sent to. The **psample** module defines the concept
              of groups, which allows the user to match specific sampled packets in the case of mul‐
              tiple sampling rules, thus identify only the packets that came from a specific rule.

       **index** _INDEX_
              Is a unique ID for an action. When creating new action instance, this parameter allows
              to set the new action index. When using existing  action,  this  parameter  allows  to
              specify the existing action index.  The index must 32bit unsigned integer greater than
              zero.

## EXAMPLES
       Sample one of every 100 packets flowing into interface eth0 to psample group 12:

              tc qdisc add dev eth0 handle ffff: ingress
              tc filter add dev eth0 parent ffff: matchall \
                   action sample rate 100 group 12 index 19

       Use the same action instance to sample eth1 too:

              tc qdisc add dev eth1 handle ffff: ingress
              tc filter add dev eth1 parent ffff: matchall \
                   action sample index 19


## SEE ALSO
       [**tc**(8)](https://www.chedong.com/phpMan.php/man/tc/8/markdown), [**tc-matchall**(8)](https://www.chedong.com/phpMan.php/man/tc-matchall/8/markdown) [**psample**(1)](https://www.chedong.com/phpMan.php/man/psample/1/markdown)



iproute2                                     31 Jan 2017               Packet sample action in [tc(8)](https://www.chedong.com/phpMan.php/man/tc/8/markdown)
