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

Add per-process network stats #62

Merged
merged 3 commits into from
Nov 10, 2022

Conversation

fearful-symmetry
Copy link
Contributor

What does this PR do?

This is one half of elastic/beats#7461

This adds per-process network stats on linux, taken from /proc/PID/net/netstat and /proc/PID/net/SNMP.
These metrics are the same kind used in the docker module for reporting docker network summary data.

This also includes a filter function, since all the data in the aforementioned two procfs files includes a prodigious amount of metrics.

There's a notable limitation here, which is that the procfs handler we're importing from go-sysinfo can't handle an alternate procfs.

Why is it important?

This is an asked-for feature.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.md

@fearful-symmetry fearful-symmetry requested a review from a team as a code owner November 10, 2022 00:05
@fearful-symmetry fearful-symmetry self-assigned this Nov 10, 2022
@fearful-symmetry fearful-symmetry requested review from rdner and faec and removed request for a team November 10, 2022 00:05
@fearful-symmetry fearful-symmetry changed the title Add process netstats Add per-process network stats Nov 10, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Nov 10, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-11-10T20:15:04.736+0000

  • Duration: 11 min 25 sec

Test stats 🧪

Test Results
Failed 0
Passed 184
Skipped 7
Total 191

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

Comment on lines +53 to +58
for k, v := range map1 {
compMap[k] = checkMaxConn(k, v)
}
for k, v := range map2 {
compMap[k] = checkMaxConn(k, v)
}
Copy link
Member

Choose a reason for hiding this comment

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

what if 2 maps have the same key, do we check twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, these values are only being merged across a given protocol, and in my experience, the kernel won't report the same metric for a given protocol twice, so it should be fine? Not sure how we would recover from that anyway, since it would seemingly be the same metric reported in two different places?

Copy link
Member

Choose a reason for hiding this comment

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

I just realised that checkMaxConn would just do a type cast, it's not really a big deal to run it twice for the same key. So, the current logic is that the second map has a priority over the first if the keys collide, which I think is fine.

Comment on lines +53 to +58
for k, v := range map1 {
compMap[k] = checkMaxConn(k, v)
}
for k, v := range map2 {
compMap[k] = checkMaxConn(k, v)
}
Copy link
Member

Choose a reason for hiding this comment

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

I just realised that checkMaxConn would just do a type cast, it's not really a big deal to run it twice for the same key. So, the current logic is that the second map has a priority over the first if the keys collide, which I think is fine.

@fearful-symmetry fearful-symmetry merged commit e2e53e9 into elastic:main Nov 10, 2022
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