Skip to content

Optimize netstat calls using /proc files (Issue #2826) - #2846

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
rohan-coder02:issue-2826-optimize-calls-to-netstat-using-proc-files
Mar 11, 2025
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
rohan-coder02:issue-2826-optimize-calls-to-netstat-using-proc-files

Conversation

@rohan-coder02

Copy link
Copy Markdown
Collaborator

Title:

Optimize calls to netstat by using /proc files (Issue #2826)

Description:

This PR optimizes the retrieval of network statistics by replacing external netstat calls with direct file reads from /proc/net/snmp (TCPv4 and UDPv4) and /proc/net/snmp6 (UDPv6).

Changes Made:

  • Replaced netstat calls with parsing /proc/net/snmp (TCPv4 and UDPv4) and /proc/net/snmp6 (UDPv6)
  • Updated LinuxInternetProtocolStats.java to extract TCP and UDP statistics

Testing Done:

  • Verified that the extracted TCP/UDP statistics match the output from cat /proc/net/snmp and cat /proc/net/snmp6
  • Confirmed correctness by comparing values before and after changes
  • Tested on various flavors of Linux such as Redhat, Amazon Linux 2, etc by creating a simple Java App and printing the TCP and UDP stats

@codecov

codecov Bot commented Mar 9, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.50%. Comparing base (8d9eda2) to head (7f89015).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2846      +/-   ##
==========================================
- Coverage   86.97%   85.50%   -1.48%     
==========================================
  Files          30       30              
  Lines        1359     1359              
  Branches      192      192              
==========================================
- Hits         1182     1162      -20     
- Misses        101      112      +11     
- Partials       76       85       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis dbwiddis 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.

First, thanks for contributing! This will be a great improvement.

I've made a few suggestions here: try to use existing parsing functions when possible. The header values are predictable so you don't need to parse them.

@dbwiddis dbwiddis 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 for your patience continuing to work on this! Logic looks good here, just some final tweaks needed.

Also please add a change log entry.

@dbwiddis dbwiddis 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.

LGTM! Thanks for this contribution, looking forward to more! 🎉

@dbwiddis dbwiddis linked an issue Mar 11, 2025 that may be closed by this pull request
@dbwiddis
dbwiddis merged commit f7641bc into oshi:master Mar 11, 2025
@rohan-coder02
rohan-coder02 deleted the issue-2826-optimize-calls-to-netstat-using-proc-files branch October 6, 2025 07:14
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.

Optimize calls to netstat by using /proc files

2 participants