Skip to content

netstat: model legacy TcpExt counters removed from recent kernels - #863

Merged
SuperQ merged 1 commit into
prometheus:masterfrom
neoLsH:add-legacy-tcpext-counters
Aug 27, 2026
Merged

netstat: model legacy TcpExt counters removed from recent kernels#863
SuperQ merged 1 commit into
prometheus:masterfrom
neoLsH:add-legacy-tcpext-counters

Conversation

@neoLsH

@neoLsH neoLsH commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What

Add 10 legacy TcpExt counters to the /proc/net/netstat model and parser:
PAWSPassive, TCPPrequeued, TCPDirectCopyFromBacklog,
TCPDirectCopyFromPrequeue, TCPPrequeueDropped, TCPLoss,
TCPFACKReorder, TCPForwardRetrans, TCPHPHitsToUser,
TCPSchedulerFailed.

Why

These counters are absent from the current kernel's TcpExt table (none of
them are in linus/master include/uapi/linux/snmp.h), but older kernels still
print them in /proc/net/netstat. node_exporter is switching its netstat
collector to these parsers (prometheus/node_exporter#3796), and would
otherwise silently drop these metrics for users whose
--collector.netstat.fields regex selects them.

Behavior

Out of scope

  • IcmpMsg / Icmp6Msg per-type counters: the kernel only prints non-zero
    InTypeN/OutTypeN entries, so the set is host-dependent and open-ended —
    a fixed struct can't cover it (a map, like NetDev, or an unknown-keys
    escape hatch would). Separate follow-up.
  • The StatValue refactor floated in netstat: Use procfs parsers for netstat, snmp and snmp6 node_exporter#3796: changing
    all netstat/snmp field types would be a breaking API change for existing
    consumers; separate discussion.

Note on scope: this PR closes the backward gap (counters older kernels print that
were never modeled). procfs's TcpExt also lags the current kernel in the other
direction (e.g. TCPDelivered, TCPAckCompressed, TCPZeroWindowDrop,
TCPBacklogCoalesce, BeyondWindow, TCPTimeoutRehash, TCPDSACKRecvSegs,
TCPMigrateReq*, TCPAO* are printed by modern kernels but not modeled). That
forward lag is procfs's ordinary upkeep, pre-exists this change, and affects all
consumers; it is deliberately out of scope here rather than bundled in.

@SuperQ

SuperQ commented Aug 27, 2026

Copy link
Copy Markdown
Member

This needs a DCO sign-off. You can use git commit -s --amend to add it.

PAWSPassive, TCPPrequeued, TCPDirectCopyFromBacklog,
TCPDirectCopyFromPrequeue, TCPPrequeueDropped, TCPLoss, TCPFACKReorder,
TCPForwardRetrans, TCPHPHitsToUser and TCPSchedulerFailed are absent from
the current kernel TcpExt table but are still printed by older kernels.
Model them so consumers keep metric parity with older kernels; the parser
stays additive (absent keys remain nil).

See prometheus/node_exporter#3796.

Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com>
@neoLsH
neoLsH force-pushed the add-legacy-tcpext-counters branch from d0574f8 to cc6d988 Compare August 27, 2026 10:07
@SuperQ
SuperQ merged commit c8c8f52 into prometheus:master Aug 27, 2026
7 checks passed
neoLsH added a commit to neoLsH/node_exporter that referenced this pull request Aug 28, 2026
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 prometheus#3796.

Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com>
neoLsH added a commit to neoLsH/node_exporter that referenced this pull request Aug 28, 2026
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 prometheus#3796.

Signed-off-by: 霏承 <huangleshu.hls@alibaba-inc.com>
SuperQ pushed a commit to prometheus/node_exporter that referenced this pull request Aug 31, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants