The
Host sFlow agent recently added support for netfilter based traffic monitoring. The
netfilter/iptables packet filtering framework is an integral part of recent Linux kernels, providing the mechanisms needed to implement firewalls and perform address translation.
Included within the netfilter framework is a
packet sampling facility. In addition to sampling packets, the netfilter framework captures the
forwarding path associated with each sampled packet, providing the essential elements needed to implement
sFlow standard traffic monitoring on a Linux system.
Instructions for installing Host sFlow are provided in the article,
Installing Host sFlow on a Linux server. In many cases configuring traffic monitoring on servers is unnecessary since sFlow capable physical and virtual switches already provide end-to-end network visibility (see
Hybrid server monitoring). However, if traffic data isn't available from the switches, either because they don't support sFlow, or because they are managed by a different organization, then traffic monitoring on the servers is required.
This article describes the additional steps needed to configure sFlow traffic monitoring using netfilter. The following steps configure 1-in-1000 sampling of packets on a Fedora 14 server. The sampling rate of 1-in-1000 was selected based on the 1Gbit speed of the network adapter. See the article,
Sampling rates, for suggested sampling rates.
First, list the existing iptables rules:
[root@fedora14 ~]# iptables --list --line-numbers --verbose
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 ACCEPT all -- lo any anywhere anywhere
2 93 8415 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
3 1 84 ACCEPT icmp -- any any anywhere anywhere
4 1 64 ACCEPT tcp -- any any anywhere anywhere state NEW tcp dpt:ssh
5 9 1138 REJECT all -- any any anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 REJECT all -- any any anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 68 packets, 9509 bytes)
num pkts bytes target prot opt in out source destination
Rules are evaluated in order, so it is important to find the correct place to apply sampling. The first rule in the
INPUT chain accepts all traffic associated with the internal loopback interface (
lo). This rule is needed because many applications use the loopback interface for inter-process communications. Since we are only interested in external traffic, the ULOG rule should be inserted as rule 2 in this rule chain:
iptables -I INPUT 2 -m statistic --mode random --probability 0.001 -j ULOG --ulog-nlgroup 5
There are currently no rules in the
OUTPUT chain, so we can simply add the ULOG rule:
iptables -A OUTPUT -m statistic --mode random --probability 0.001 -j ULOG --ulog-nlgroup 5
Note: Sampling rates are expressed as probabilities, so the sampling rate of 1-in-1000 translates to a probability of
0.001. Only add one sFlow sampling rule to each chain. Duplicate sampling rules will result in biased measurements since the probability of sampling a packet will vary depending on where it matches in the chain. Use the same sampling probability in both INPUT and OUTPUT chains for the same reason.
Note: There are 32 netlink groups (1-32) that can be used to transmit ULOG messages. Check to see if there are any other ULOG statements in iptables and make sure to select a distinct group for sFlow sampling. In this case group
5 has been selected.
Listing the table again confirms that the changes are correct:
[root@fedora14 ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ULOG all -- anywhere anywhere statistic mode random probability 0.001000 ULOG copy_range 0 nlgroup 5 queue_threshold 1
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ULOG all -- anywhere anywhere statistic mode random probability 0.001000 ULOG copy_range 0 nlgroup 5 queue_threshold 1
In many deployments, servers are running in a secure network behind a firewall and so the overhead of running a stateful firewall on each server is unnecessary. In this case a very simple, monitoring only, configuration of iptables provides traffic visibility with minimal impact on server performance:
[root@fedora14 ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ULOG all -- anywhere anywhere statistic mode random probability 0.001000 ULOG copy_range 0 nlgroup 5 queue_threshold 1
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ULOG all -- anywhere anywhere statistic mode random probability 0.001000 ULOG copy_range 0 nlgroup 5 queue_threshold 1
Once the rules are correct, they should be saved so that they will automatically be reinstalled if the server is rebooted.
[root@fedora14 ~]# service iptables save
The Host sFlow agent needs to be configured to export the samples (by editing the
/etc/hsflowd.conf file). The following configuration instructs the Host sFlow agent to use
DNS-SD to automatically configure sFlow receivers and polling intervals. The additional ULOG settings tell the agent which ULOG nlgroup to listen to for packet samples as well as the sampling probability that was configured in iptables:
sflow {
DNSSD = on
# ULOG settings
ulogProbability = 0.001
ulogGroup = 5
}
Note: Make sure that the sampling probability specified in the Host sFlow configuration matches the probability used in the iptables rules. Any discrepancies will result in incorrectly scaled traffic measurements.
Next, restart the Host sFlow agent so that it picks up the new configuration:
[root@fedora14 ~]# service hsflowd restart
Note: The Host sFlow agent can resample ULOG captured packets in order to achieve the sampling rate specified using DNS-SD, or through the
sampling setting in the
/etc/hsflowd.conf file. Choose a relatively aggressive ULOG sampling probability that reduces the overhead of monitoring, but allows a wide range of sampling rates to be set. For example, configuring the ULOG probability to 0.01 will allow Host sFlow agent sampling rates to be set to 100, 200, 300, 400 etc. The Host sFlow agent will choose the nearest sampling rate it can achieve, so if you configure a sampling rate of 290, it would actually sample with a rate of 300 (i.e. sample every third ULOG packet).
At this point traffic data from the server should start appearing in the sFlow analyzer. The following chart shows top connections monitored using ULOG/Host sFlow:
Finally, sFlow monitoring of servers is part of an overall solution that simplifies management by unifying network, storage, server and application performance monitoring within a single scalable system (see
sFlow Host Structures). Implementing an sFlow monitoring solution helps break down
management silos, ensuring the coordination of resources needed to manage a
converged infrastructure.