Skip to content

Comments

Add TCP state collector#56

Merged
juliusv merged 1 commit intoprometheus:masterfrom
kjmkznr:add-tcp-stat-collector
Mar 24, 2015
Merged

Add TCP state collector#56
juliusv merged 1 commit intoprometheus:masterfrom
kjmkznr:add-tcp-stat-collector

Conversation

@kjmkznr
Copy link
Contributor

@kjmkznr kjmkznr commented Mar 20, 2015

This collector expose following metrics:

  • Number of TCP ESTABLISHED connections
  • Number of TCP LISTEN ports
  • Number of TCP SYN_SENT state connections
  • Number of TCP SYN_RECV state connections
  • Number of TCP FIN_WAIT1 state connections
  • Number of TCP FIN_WATI2 state connections
  • Number of TCP TIME_WAIT state connections
  • Number of TCP CLOSE state connections
  • Number of TCP CLOSE_WAIT state connections
  • Number of TCP LAST_ACK state connections
  • Number of TCP CLOSING state connections

Copy link
Contributor

Choose a reason for hiding this comment

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

/proc/net/tcp is n^3, if you need this information you need to use the same syscalls ss(1) does.

Copy link
Member

Choose a reason for hiding this comment

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

ss uses Netlink sockets under the hood. From strace:

Request for data:

socket(PF_NETLINK, SOCK_RAW, 4)         = 3
sendmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"L\0\0\0\22\0\1\3@\342\1\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 76}], msg_controllen=0, msg_flags=0}, 0) = 76

Reading data:

recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"`\0\0\0\22\0\2\0@\342\1\0\2127\0\0\n\10\0\0\2408\2w\0\0\0\0\0\0\0\0"..., 8192}], msg_controllen=0, msg_flags=0}, 0) = 1344

Go seems to support Netlink (http://golang.org/pkg/syscall), so this should be doable... let me know if I can help build that code.

Copy link
Contributor

Choose a reason for hiding this comment

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

When I looked into this a few years back the API ss used wasn't very mature. I ended up shelling out to ss on that occasion, which isn't an option here.

Copy link
Member

Choose a reason for hiding this comment

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

Wasn't mature in what sense? It was undergoing breaking changes (unlikely with kernel interfaces), or it didn't work correctly yet? Or just not available in older kernels?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seemed more of a thing to get just ss(1) working, rather than a generic solution with library support.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds to me like reading /proc is the better option at least until it proves necessary to optimize further?

Copy link
Member

Choose a reason for hiding this comment

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

@matthiasr Yeah, the only problem is that it might accidentally really slow down people's node exporters or machines especially in high-load situations (tens of thousands of connections).

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's use the /proc/net/tcp support until someone manages to write Netlink code, but let's not enable this collector by default (that's already the case, so no change needed regarding that).

@juliusv
Copy link
Member

juliusv commented Mar 22, 2015

👍 besides the minor style nits and the question about whether to put IPv4/IPv6 into a label.

Thanks for bearing with us!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I have added modification. (93d21b5)
Fix always error on not exists /proc/net/tcp6.

@juliusv
Copy link
Member

juliusv commented Mar 23, 2015

@kjmkznr Cool, looks good to me for now, and we can still add extra labels later or improve the way how we get the TCP stats (netlink). Could you squash your commits? Then I'll merge.

@brian-brazil
Copy link
Contributor

The readme needs to be updated too, with a warning about the performance issue.

@juliusv
Copy link
Member

juliusv commented Mar 23, 2015

Good point.

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Mar 24, 2015

Update readme.
If no problem, I create new pull request and squash commits.

README.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Some minor things here, can we do:

"Exposes TCP connection status information from /proc/net/tcp and /proc/net/tcp6. (Warning: the current version has potential performance issues in high load situations.)"

@juliusv
Copy link
Member

juliusv commented Mar 24, 2015

@kjmkznr Hm, why would you create a new PR? Usually you can just squash the commits in the existing PR.

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Mar 24, 2015

@juliusv Can I force push to current branch?

@juliusv
Copy link
Member

juliusv commented Mar 24, 2015

Yup!

@kjmkznr kjmkznr force-pushed the add-tcp-stat-collector branch from f654b16 to 30280d5 Compare March 24, 2015 11:28
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Mar 24, 2015

I didn't know github spec. Thanks!
I pushed squashed commit.

@juliusv
Copy link
Member

juliusv commented Mar 24, 2015

@kjmkznr Cool, could you just still integrate this comment before merging? https://github.com/prometheus/node_exporter/pull/56/files#r27012081

@kjmkznr kjmkznr force-pushed the add-tcp-stat-collector branch from 30280d5 to e4da771 Compare March 24, 2015 11:35
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Mar 24, 2015

I overlooked that.
I pushed again.

@juliusv
Copy link
Member

juliusv commented Mar 24, 2015

@kjmkznr Thanks a bunch!

juliusv added a commit that referenced this pull request Mar 24, 2015
@juliusv juliusv merged commit 3ab0b1f into prometheus:master Mar 24, 2015
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Mar 24, 2015

Thanks!
2015/03/24 20:50 "Julius Volz" notifications@github.com:

Merged #56 #56.


Reply to this email directly or view it on GitHub
#56 (comment).

tamcore pushed a commit to gitgrave/node_exporter that referenced this pull request Oct 22, 2024
Replace fixtures.tar.gz with regular files
tamcore pushed a commit to gitgrave/node_exporter that referenced this pull request Oct 22, 2024
The generated pathnames are too long for some filenames, including NTFS
in its default configuration. We've considered using other separators,
but deemed shorter ones to easy to break something.

This reverts commit b9955ae, reversing
changes made to a3bfc74.

Fixes prometheus#57.
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.

4 participants