Repository navigation
Add raw access to map structures in proc filesystem - #2854
Conversation
|
Thanks for this library! I'd like to propose the provided additions which would be very useful in the project I work on. These 'raw' access methods simply provide a means to access various statistics without needing specific API calls/methods for each individual statistic. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2854 +/- ##
==========================================
- Coverage 87.19% 85.73% -1.47%
==========================================
Files 30 31 +1
Lines 1359 1395 +36
Branches 192 202 +10
==========================================
+ Hits 1185 1196 +11
- Misses 100 113 +13
- Partials 74 86 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mprins
left a comment
There was a problem hiding this comment.
there are some checkstyle errors:
[INFO] Starting audit...
Error: /home/runner/work/oshi/oshi/oshi-core/src/main/java/oshi/software/os/linux/LinuxInternetProtocolStats.java:176:74: Expected @param tag for 'procFile'. [JavadocMethod]
Error: /home/runner/work/oshi/oshi/oshi-core/src/main/java/oshi/software/os/linux/LinuxInternetProtocolStats.java:243:43: File contains tab characters (this is the first instance). [FileTabCharacter]
Error: /home/runner/work/oshi/oshi/oshi-core/src/test/java/oshi/software/os/linux/LinuxInternetProtocolStatsTest.java:8:1: Disallowed import - java.net.URL. [ImportControlTest]
Audit done.
[INFO] There are 3 errors reported by Checkstyle 10.21.4 with config/checkstyle.xml ruleset.
Error: src/main/java/oshi/software/os/linux/LinuxInternetProtocolStats.java:[176,74] (javadoc) JavadocMethod: Expected @param tag for 'procFile'.
Error: src/main/java/oshi/software/os/linux/LinuxInternetProtocolStats.java:[243,43] (whitespace) FileTabCharacter: File contains tab characters (this is the first instance).
Error: src/test/java/oshi/software/os/linux/LinuxInternetProtocolStatsTest.java:[8,1] (extension) ImportControlTest: Disallowed import - java.net.URL.
|
Hey @jdeppe-pivotal thanks for this contribution! I agree we should make it easier to expose "all" data from the proc filesystem available in generic key/value maps. The one thing that gave me pause when initially reviewing this is exposing a platform-specific package as a JPMS module, as it somewhat breaks the "this is the API" model, particularly for the "hardware" and "software" package trees. We do currently have WDYT about creating a You could probably just have more generic "getFooMap" methods there for the different styles such as a prefix with headers and values on successive lines which is essentially what you've written in |
|
@dbwiddis Thanks for the suggestions. I've:
|
I think it depends on how many methods we're adding, but I'm leaning more toward a
Well, it has a |
dbwiddis
left a comment
There was a problem hiding this comment.
Looks good pending the string length check (can probably add parts[0].isEmpty() to the conditional on the line above).
Also please add a change log entry.
Provide methods to process and marshall the named /proc files into a
consistent map structure of { key: { stat: value }}.
- Moved method into ProcUtil - Removed processNetSnmp6 since FileUtils.getKeyValueMapFromFile should suffice.
…hitespace separator.
9b2c738 to
7aa9d25
Compare
dbwiddis
left a comment
There was a problem hiding this comment.
Looks great! I'll merge when tests finish.
|
Thanks @dbwiddis ! |
getUDPv6Stats() passed its four counters to UdpStats in the order /proc/net/snmp6 lists them rather than the order the constructor takes them, so every field held another field's value: datagrams sent reported those received, received reported those dropped for no port, no port reported the input errors, and received errors reported those sent. getUDPv4Stats() had the same rotation, hidden one level down. It mapped the /proc/net/snmp columns positionally with ParseUtil.stringToEnumMap, and the private UdpStat enum declared OutDatagrams first while the kernel emits it fourth, after InDatagrams, NoPorts and InErrors. Both are now read through ProcUtil, which keys each counter by its name in the file, so a column order that does not match cannot misalign the fields. That retires the two hand-rolled parsers along with the ordinal coupling, and gives ProcUtil, added in #2854 for exactly these two files, its first caller. TCPv4 moves across unchanged in behavior; its enum order already matched the kernel's. Verified against a live kernel by generating 15 sent, 7 received and 3 no-port datagrams over both IPv4 and IPv6 and comparing OSHI's deltas to the /proc counter deltas: 7.7.1 misses all eight, this passes all eight.
Provide methods to process and marshal the named /proc files into
a consistent map structure of
{ key: { stat: value }}.