netstat: Use procfs parsers for netstat, snmp and snmp6 (#3796)
* netstat: Use procfs parsers for netstat, snmp and snmp6 Replace the hand-written parsers for /proc/net/netstat, /proc/net/snmp and /proc/net/snmp6 with the parsers from prometheus/procfs (Proc.Netstat, Proc.Snmp and Proc.Snmp6). The statistics are read via /proc/self/net, which is equivalent to /proc/net (both are network-namespace local views of the current process), so the collected data is unchanged. Metrics are exposed by iterating the procfs statistics structs, the same approach the NFS collector uses: fields are *float64 and only the ones present on the system are exported, matching the previous behavior. The --collector.netstat.fields flag and the exported metric names are unchanged; the e2e golden output is identical. Signed-off-by: neoLsH <43921685+neoLsH@users.noreply.github.com> * netstat: use explicit package-level metric descriptors Replace the per-scrape prometheus.NewDesc calls with a pre-built map of explicit descriptors (netstat_descs_linux.go, generated from the procfs statistics structs), as requested in review. Collection still reflects over the procfs structs but looks up the descriptor by "<protocol>_<field>", so descriptors are allocated once and are source-visible literals for the AST-based doc generation. Metric names, help strings and types are unchanged. Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com> * Bump procfs to v0.22.0 to populate legacy TcpExt descriptors procfs v0.22.0 includes prometheus/procfs#863, which models the 10 legacy TcpExt counters. With this bump, the explicit descriptors already present in netstat_descs_linux.go start populating for users whose field regex selects them, restoring parity with older kernels. Part of #3796. Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com> * Add generator and drift test for the netstat descriptor table netstat_descs_linux.go was previously committed without its generator. Add an in-repo generator (netstat_descs_gen.go, a build-ignored program run via GOOS=linux go generate ./collector) that regenerates the explicit descriptor table from the procfs structs, mirroring the go:generate pattern used elsewhere in the Prometheus ecosystem. Add TestNetStatDescsInSync, a drift test that fails if the committed table diverges from the procfs structs (e.g. after a procfs upgrade) until the table is regenerated. Part of #3796. Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com> --------- Signed-off-by: neoLsH <43921685+neoLsH@users.noreply.github.com> Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com>
N
neoLsH committed
794e058b51d43ed089e739370889761a3ffe7d01
Parent: 9a07737
Committed by GitHub <noreply@github.com>
on 8/31/2026, 1:29:08 PM