Skip to content

netstat_freebsd: add new metrics #3334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

daniloegea
Copy link

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

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]>
@daniloegea
Copy link
Author

daniloegea commented May 16, 2025

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

@Rin0913, do you have any comments?

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.

1 participant