Why Interface Counters Stop Being Useful
Once a VPS has more than one network interface, the kernel’s per-interface byte counters tell you a total and nothing about where traffic came from. On a machine that bridges two interfaces or carries several VLAN sub-interfaces, a spike on the parent device might be legitimate traffic from one container, a broadcast storm from a misconfigured bridge, or a loop you introduced while testing. The aggregate counter cannot distinguish them, and by the time you notice, the damage is done.
The alternative is to observe at the point where the kernel decides what to do with a packet, using eBPF attached to the traffic control and socket layers. On a KVM guest these programs run inside your own kernel, need no privileges beyond what root already has, and add measurably less overhead than a packet capture writing to disk. The goal is a small set of counters keyed by interface, VLAN ID, and protocol, sampled continuously rather than in a five-second panic.
Where to Attach: TC Ingress Versus Egress
Traffic control hooks exist on both sides of the device. An ingress hook sees frames arriving before the bridge decides whether to forward or consume them, which is exactly where you want to count duplicate broadcasts and VLAN-tagged frames. An egress hook sees frames after routing and bridging, which is where you count what actually left the box.
Attaching both gives you a per-interface view of arrival and departure that is far more precise than the kernel counters, because you control the classification. Attach the program with the classifier action set to pass so it observes without altering forwarding behavior. A program that returns drop by accident will take the interface down, and on a remote VPS that is an outage you inflict on yourself.
Classifying by VLAN and Bridge Port
Inside the program you can read the Ethernet header directly and extract the 802.1Q tag, the source and destination MAC, and the ethertype. Group those into a small set of keys: VLAN identifier, bridge port index, and protocol family. Store the counts in a per-CPU hash map so that updates need no locking, then aggregate on read. This avoids the contention that makes naive shared counters inaccurate under high packet rates.
tc qdisc add dev br0 clsact
tc filter add dev br0 ingress bpf da obj count.o sec ingress
bpftool map dump name vlan_counts
Reading the bridge port index from the skb metadata lets you distinguish traffic that arrived from a container on veth3 from traffic that arrived from the physical uplink, even though both enter through br0. That single distinction resolves most “why is my bridge busy” questions without a packet capture.
Measuring the Overhead Before You Trust the Data
An observation program is still code running on every packet, so measure it before deploying it broadly. Run your usual throughput test twice, once with the program attached and once with the classifier removed, on the same instance within a few minutes of each other. Express the result as a percentage of baseline throughput rather than an absolute number, since absolute numbers move with the host’s load.
A simple counter program that only increments a per-CPU map typically costs under a few percent on a virtio interface at moderate rates. If you see a double-digit drop, the program is probably doing something expensive per packet, such as calling a helper that walks a structure or allocating memory in the hot path. Move that work to the userspace reader instead.
Detecting Broadcast Storms and Bridge Loops
The most common bridge failure mode is a loop: two paths between the same segments, or a container network that forward frames back to the bridge. The symptom is a broadcast rate that grows until the link saturates. With per-port ingress counters you can see which port is sourcing the storm, because the rate on that port will be orders of magnitude above the others and will be dominated by broadcast and multicast destinations.
Track the ratio of broadcast to unicast per port and alert on a sustained shift rather than a single sample. A brief burst during ARP resolution is normal; a rate that stays high for more than a few seconds while total throughput climbs is the signature of a loop. Because the classification happens before forwarding, you can also export the offending source MAC and go straight to the interface that owns it.
Correlating With Sockets and Containers
Interface-level counts tell you which port is busy but not which process owns the traffic. Pair the network program with a socket-layer program that records the process identifier and cgroup for established connections, then join the two on the five-tuple. On a guest running containers, the cgroup identifier maps directly to a container, which turns an abstract bridge counter into a named tenant.
Keep the join in userspace. Programs that try to resolve a process identifier while handling a packet in the kernel are both slower and harder to reason about, and the socket program can record the mapping at connect time when the information is reliable. Export both streams to a local collector and join them offline, where you can re-run the analysis without touching the live system.
A Workflow That Scales to Several Hosts
Ship the same compiled program to every host and let a small agent load it, so that the counters share a schema and can be compared across machines. A template that also carries a configuration map lets you change which VLANs or ports are tracked without recompiling. On a fleet of budget instances this consistency is worth more than any single dashboard.
Start by instrumenting one bridge on the instance that has shown the problem, confirm the overhead figure, then roll out to the rest. For the base configuration these programs attach to, see the VPS networking and kernel documentation, and check the baseline packet-rate figures so you know what normal looks like before you go looking for anomalies.




Leave a Reply
You must be logged in to post a comment.