Skip to content

netstat: Add new FreeBSD metrics - #3334

Merged
SuperQ merged 6 commits into
prometheus:masterfrom
daniloegea:netstat_freebsd
Jul 12, 2026
Merged

SuperQ merged 6 commits into
prometheus:masterfrom
daniloegea:netstat_freebsd

Conversation

@daniloegea

Copy link
Copy Markdown
Contributor

This PR adds a number of new metrics to the netstat_freebsd module.

The first commit is a refactoring to make it easier to add new metrics. It also fixes the netstat_freebsd tests, which were completely broken. I added a function to return fake raw data so the code can be tested without calling the low level functions.

The new metrics are:

IPv4

ip4_transmit_packets_total
ip4_transmit_raw_packets_total
ip4_receive_packets_total
ip4_receive_fragments_total
ip4_forward_total
ip4_fast_forward_total
ip4_delivered_total

IPv6

ip6_transmit_packets_total
ip6_transmit_raw_packets_total
ip6_receive_packets_total
ip6_receive_fragments_total
ip6_forward_total
ip6_delivered_total

UDP

udp_transmit_packets_total
udp_receive_packets_total

TCP states

node_netstat_tcp_connections{state="CLOSED"}
node_netstat_tcp_connections{state="CLOSE_WAIT"}
node_netstat_tcp_connections{state="CLOSING"}
node_netstat_tcp_connections{state="ESTABLISHED"}
node_netstat_tcp_connections{state="FIN_WAIT_1"}
node_netstat_tcp_connections{state="FIN_WAIT_2"}
node_netstat_tcp_connections{state="LAST_ACK"}
node_netstat_tcp_connections{state="LISTEN"}
node_netstat_tcp_connections{state="SYN_RCVD"}
node_netstat_tcp_connections{state="SYN_SENT"}
node_netstat_tcp_connections{state="TIME_WAIT"}

Each commit has the list of metrics added, but here is the full list (including the ones that already existed):

# HELP node_netstat_ip4_delivered_total IPv4 packets delivered to the upper layer (packets for this host)
# TYPE node_netstat_ip4_delivered_total counter
node_netstat_ip4_delivered_total 1.5222157e+07
# HELP node_netstat_ip4_fast_forward_total IPv4 packets fast forwarded
# TYPE node_netstat_ip4_fast_forward_total counter
node_netstat_ip4_fast_forward_total 3.029054e+06
# HELP node_netstat_ip4_forward_total IPv4 packets forwarded
# TYPE node_netstat_ip4_forward_total counter
node_netstat_ip4_forward_total 1.0136014e+07
# HELP node_netstat_ip4_receive_fragments_total IPv4 fragments received
# TYPE node_netstat_ip4_receive_fragments_total counter
node_netstat_ip4_receive_fragments_total 0
# HELP node_netstat_ip4_receive_packets_total IPv4 packets received
# TYPE node_netstat_ip4_receive_packets_total counter
node_netstat_ip4_receive_packets_total 2.9040874e+07
# HELP node_netstat_ip4_transmit_packets_total IPv4 packets sent from this host
# TYPE node_netstat_ip4_transmit_packets_total counter
node_netstat_ip4_transmit_packets_total 1.308442e+07
# HELP node_netstat_ip4_transmit_raw_packets_total IPv4 raw packets generated
# TYPE node_netstat_ip4_transmit_raw_packets_total counter
node_netstat_ip4_transmit_raw_packets_total 262462
# HELP node_netstat_ip6_delivered_total IPv6 packets delivered to the upper layer (packets for this host)
# TYPE node_netstat_ip6_delivered_total counter
node_netstat_ip6_delivered_total 8.272913e+06
# HELP node_netstat_ip6_forward_total IPv6 packets forwarded
# TYPE node_netstat_ip6_forward_total counter
node_netstat_ip6_forward_total 0
# HELP node_netstat_ip6_receive_fragments_total IPv6 fragments received
# TYPE node_netstat_ip6_receive_fragments_total counter
node_netstat_ip6_receive_fragments_total 0
# HELP node_netstat_ip6_receive_packets_total IPv6 packets received
# TYPE node_netstat_ip6_receive_packets_total counter
node_netstat_ip6_receive_packets_total 8.363273e+06
# HELP node_netstat_ip6_transmit_packets_total IPv6 packets sent from this host
# TYPE node_netstat_ip6_transmit_packets_total counter
node_netstat_ip6_transmit_packets_total 5.106645e+06
# HELP node_netstat_ip6_transmit_raw_packets_total IPv6 raw packets generated
# TYPE node_netstat_ip6_transmit_raw_packets_total counter
node_netstat_ip6_transmit_raw_packets_total 0
# HELP node_netstat_tcp_connections Number of TCP connections per state
# TYPE node_netstat_tcp_connections gauge
node_netstat_tcp_connections{state="CLOSED"} 1
node_netstat_tcp_connections{state="CLOSE_WAIT"} 0
node_netstat_tcp_connections{state="CLOSING"} 138
node_netstat_tcp_connections{state="ESTABLISHED"} 39
node_netstat_tcp_connections{state="FIN_WAIT_1"} 0
node_netstat_tcp_connections{state="FIN_WAIT_2"} 0
node_netstat_tcp_connections{state="LAST_ACK"} 2
node_netstat_tcp_connections{state="LISTEN"} 10
node_netstat_tcp_connections{state="SYN_RCVD"} 0
node_netstat_tcp_connections{state="SYN_SENT"} 0
node_netstat_tcp_connections{state="TIME_WAIT"} 0
# HELP node_netstat_tcp_receive_packets_total TCP packets received
# TYPE node_netstat_tcp_receive_packets_total counter
node_netstat_tcp_receive_packets_total 2.1505317e+07
# HELP node_netstat_tcp_transmit_packets_total TCP packets sent
# TYPE node_netstat_tcp_transmit_packets_total counter
node_netstat_tcp_transmit_packets_total 1.6645327e+07
# HELP node_netstat_udp_receive_packets_total UDP packets received
# TYPE node_netstat_udp_receive_packets_total counter
node_netstat_udp_receive_packets_total 1.987699e+06
# HELP node_netstat_udp_transmit_packets_total UDP packets sent
# TYPE node_netstat_udp_transmit_packets_total counter
node_netstat_udp_transmit_packets_total 1.170068e+06

@daniloegea

daniloegea commented May 16, 2025 •

Copy link
Copy Markdown
Contributor Author

Hm, I just found this PR #3292. I suppose I can include those metrics here as well.

@Rin0913, do you have any comments?

@Rin0913

Rin0913 commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

@daniloegea Sure, as you want.

@SuperQ SuperQ changed the title netstat_freebsd: add new metrics netstat: Add new FreeBSD metrics Jul 10, 2026

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the end-to-end test fixture with the new metrics.

@daniloegea

Copy link
Copy Markdown
Contributor Author

Hi, as they are non-deterministic network metrics, should I add them to the non_deterministic_metrics list in the end-to-end-test.sh script?

@SuperQ

SuperQ commented Jul 12, 2026

Copy link
Copy Markdown
Member

Yes, add them to the non-deterministic list.

Make the code testable and more maintainable:
- Encapsulate all the CGO code so it can be tested
- Fix the test file (it wasn't compiling) and improve tests
- Mock the data returned by unix.SysctlRaw so the code can be tested
  without actually calling sysctl.

No change in behavior intended

Signed-off-by: Danilo Egea Gondolfo <[email protected]>
Metrics added:
- ip4_transmit_packets_total
- ip4_transmit_raw_packets_total
- ip4_receive_packets_total
- ip4_receive_fragments_total
- ip4_forward_total
- ip4_fast_forward_total
- ip4_delivered_total

Signed-off-by: Danilo Egea Gondolfo <[email protected]>
Metrics added:
- ip6_transmit_packets_total
- ip6_transmit_raw_packets_total
- ip6_receive_packets_total
- ip6_receive_fragments_total
- ip6_forward_total
- ip6_delivered_total

Signed-off-by: Danilo Egea Gondolfo <[email protected]>
Metrics added:
- udp_transmit_packets_total
- udp_receive_packets_total

Signed-off-by: Danilo Egea Gondolfo <[email protected]>
Metric added (gauge):
node_netstat_tcp_connections{state="CLOSED"}
node_netstat_tcp_connections{state="CLOSE_WAIT"}
node_netstat_tcp_connections{state="CLOSING"}
node_netstat_tcp_connections{state="ESTABLISHED"}
node_netstat_tcp_connections{state="FIN_WAIT_1"}
node_netstat_tcp_connections{state="FIN_WAIT_2"}
node_netstat_tcp_connections{state="LAST_ACK"}
node_netstat_tcp_connections{state="LISTEN"}
node_netstat_tcp_connections{state="SYN_RCVD"}
node_netstat_tcp_connections{state="SYN_SENT"}
node_netstat_tcp_connections{state="TIME_WAIT"}

Signed-off-by: Danilo Egea Gondolfo <[email protected]>
The new metrics are non-deterministic so add them to the
non_deterministic_metrics list in the end-to-end-test.sh script.

Signed-off-by: Danilo Egea Gondolfo <[email protected]>

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SuperQ
SuperQ merged commit 47ded75 into prometheus:master Jul 12, 2026
17 checks passed
@SuperQ SuperQ mentioned this pull request Nov 18, 2026
SuperQ added a commit that referenced this pull request Nov 18, 2026
The behavior of `node_cpu_frequency_hertz` has changed. There are two different sources
of data for this metric. One from the `cpu` collector, one from the `cpufreq` collector.
Due to historical feature migrations the `cpufreq` collector shares the same subsystem
as the `cpu` collector. This caused conflicting data behavior. An attempt to fix this
was introduced in #3318. This behavior has been reverted to the previous behavior in #3795.

A new flag (`--collector.cpufreq.enable-cpufreq-prefix`) has been introduced that gives
the `cpufreq` a dedicated metric name subsystem (`node_cpufreq_...`). This will likely
be the default in v2.

* [CHANGE] netstat: Use procfs parsers for netstat, snmp and snmp6 #3796
* [CHANGE] edac: Fix no data results #3863
* [CHANGE] nvme: Deprecate metric nvme_namespace_capacity_bytes #3899
* [FEATURE] Add tainted collector for /proc/sys/kernel/tainted #3745
* [FEATURE] Add resctrl collector #3797
* [ENHANCEMENT] netstat: Add new FreeBSD metrics #3334
* [ENHANCEMENT] Add `chip` label to DRM metrics #3572
* [ENHANCEMENT] diskstats: add device-mapper backing device info metric #3676
* [ENHANCEMENT] textfile: support UTF-8 metric and label names #3729
* [ENHANCEMENT] ksmd: add general_profit metric #3778 #3894
* [BUGFIX] edac: Fix printf-style formatting in slog call #3759
* [BUGFIX] fibre_channel: fix crash when attempting to dereference invalid counters #3573
* [BUGFIX] thermal: Fix collecting Darwin temperatures without CPU power status #3767
* [BUGFIX] fibrechannel: Fix for ppc64le #3769
* [BUGFIX] cpu: Revert dup cpu frequency, add node_cpufreq flag #3795
* [BUGFIX] infiniband: skip sysfs reads for excluded devices #3824
* [BUGFIX] bcache: Fix btree_read_average_duration_seconds unit #3828

Signed-off-by: Ben Kochie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants