Skip to content
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

tcp: use GetExtendedTcpTable to display states Closed, Listening, SynSent, SynRcvd, CloseWait, TimeWait ... #1638

Merged
merged 25 commits into from
Oct 1, 2024

Conversation

astigmata
Copy link
Contributor

@astigmata astigmata commented Sep 24, 2024

Windows API Integration

The program interacts with the Windows API using syscalls to access low-level TCP information:

It loads the iphlpapi.dll library and uses the GetExtendedTcpTable function to retrieve TCP connection information.

The MIB_TCPROW_OWNER_PID struct is defined to represent a row in the TCP connection table.

# HELP windows_tcp_connections_state_count Number of TCP connections by state and address family
# TYPE windows_tcp_connections_state_count gauge
windows_tcp_connections_state_count{af="ipv4",state="CLOSE_WAIT"} 2
windows_tcp_connections_state_count{af="ipv4",state="ESTABLISHED"} 9
windows_tcp_connections_state_count{af="ipv4",state="LISTENING"} 14
windows_tcp_connections_state_count{af="ipv6",state="ESTABLISHED"} 4
windows_tcp_connections_state_count{af="ipv6",state="LISTENING"} 11
windows_tcp_connections_state_count{af="ipv6",state="TIME_WAIT"} 2

@astigmata astigmata requested a review from a team as a code owner September 24, 2024 12:31
@astigmata astigmata force-pushed the tcp_probes branch 2 times, most recently from fc70d17 to 35f4322 Compare September 24, 2024 13:31
@jkroepke jkroepke changed the title Use GetExtendedTcpTable to display states Closed, Listening, SynSent, SynRcvd, CloseWait, TimeWait ... tcp: se GetExtendedTcpTable to display states Closed, Listening, SynSent, SynRcvd, CloseWait, TimeWait ... Sep 24, 2024
@jkroepke jkroepke changed the title tcp: se GetExtendedTcpTable to display states Closed, Listening, SynSent, SynRcvd, CloseWait, TimeWait ... tcp: use GetExtendedTcpTable to display states Closed, Listening, SynSent, SynRcvd, CloseWait, TimeWait ... Sep 24, 2024
@jkroepke
Copy link
Member

jkroepke commented Sep 24, 2024

Hi @astigmata

great PR so far! I liked that WMI is not used. But it needs to be restructured a little bit. Do you have an example output of the metrics?

In another PR (#1635), I'm also start to use iphlpapi.dll to gain informations about routes.

Since the multiple collection may use iphlpapi.dll, the logic to Windows API should be separated to an dedicated packages, like I did it in https://github.com/prometheus-community/windows_exporter/pull/1635/files


btw. in 99% of all cases, golang.org/x/sys/windows is an drop-in replacement for syscall, e.g. windows.AF_INET instead syscall.AF_INET

pkg/collector/tcp/tcp.go Outdated Show resolved Hide resolved
@astigmata astigmata requested a review from jkroepke September 24, 2024 20:50
pkg/collector/tcp/tcp.go Outdated Show resolved Hide resolved
pkg/collector/tcp/tcp.go Outdated Show resolved Hide resolved
pkg/headers/iphlpapi/types.go Outdated Show resolved Hide resolved
pkg/headers/iphlpapi/iphlpapi.go Outdated Show resolved Hide resolved
@jkroepke
Copy link
Member

@astigmata After a review, I can take the lint issues, thats fine!

jkroepke and others added 17 commits September 26, 2024 18:45
…rometheus-community#1603)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: astigmata <[email protected]>
Signed-off-by: astigmata <[email protected]>
Signed-off-by: astigmata <[email protected]>
astigmata and others added 4 commits September 26, 2024 18:45
jkroepke and others added 3 commits September 26, 2024 18:47
Signed-off-by: Jan-Otto Kröpke <[email protected]>
Signed-off-by: Jan-Otto Kröpke <[email protected]>
@astigmata
Copy link
Contributor Author

@astigmata After a review, I can take the lint issues, thats fine!

@jkroepke Thank you for the help, it's my first contrib

@jkroepke
Copy link
Member

jkroepke commented Sep 26, 2024

Oh, you did it very well for the first contribution! :-)

I will leave it open for now, because I would like to deliver some bug-fix only releases in context of 0.29.0, but this PR will be included in the next 0.30.0 release!

Thank you!

Copy link
Member

@jkroepke jkroepke left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@jkroepke jkroepke merged commit 1caef5c into prometheus-community:master Oct 1, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants