AS215855 /INDEPENDENT BY DESIGN
← All posts
Jul 25, 2025 · TOMAS JONSSON · 2 MIN READ

Adding BGP Prefix Length Statistics to BIRD Exporter

Understanding prefix length distribution in a full BGP routing table with Prometheus metrics.

asn215855bird2grafanaprometheus

When managing a BGP full routing table containing approximately 220,000 IPv6 routes, network engineers need visibility into prefix length distribution. I sought to understand how many /48, /32, and /44 prefixes exist within my routing table, but discovered that the popular bird_exporter for Prometheus didn't provide this granularity.

The Challenge

The bird_exporter tool offered excellent metrics for BGP session health and route counts, yet lacked the ability to break down routes by prefix length. A direct approach—querying all routes and parsing their lengths—created a critical problem: Unix socket buffer overflow when processing 220,000 routes generating approximately 880,000 lines of output.

The Solution

Rather than parsing complete route details, I leveraged BIRD v2's efficient count functionality. Specific queries like:

show route table master6 where net ~ [::/0{48,48}] primary count

returned only essential data—the count of matching prefixes.

Key implementation details included:

Results

The implementation exports Prometheus metrics tracking prefix length distribution across routing tables, with separate metrics for IPv4 and IPv6. The data revealed diverse prefix allocations, with /48 prefixes comprising 99,344 routes and /32 prefixes totaling 25,763 routes in the master6 table.

Technical Insights

Three lessons learned: leverage built-in count capabilities rather than parsing, respect system buffer limitations, and validate solutions against real-world datasets. The complete implementation is available on GitHub.

← Back to the archive