Package oshi.util
Class ProcUtil
java.lang.Object
oshi.util.ProcUtil
-
Method Summary
Modifier and TypeMethodDescriptionparseNestedStatistics
(String procFile, String... keys) Parses /proc files with a given structure consisting of a keyed header line followed by a keyed value line.parseStatistics
(String procFile) OverloadedparseStatistics(String, Pattern)
using a whitespace separator.parseStatistics
(String procFile, Pattern separator) Parses /proc files formatted as "statistic (long)value" to produce a simple mapping.
-
Method Details
-
parseNestedStatistics
Parses /proc files with a given structure consisting of a keyed header line followed by a keyed value line./proc/net/netstat
and/proc/net/snmp
are specific examples of this. The returned map is of the form {key: {stat: value, stat: value, ...}}. An example of the file structure is:TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed ... TcpExt: 0 4 0 ... IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts ... IpExt: 55 0 27786 1435 ... MPTcpExt: MPCapableSYNRX MPCapableSYNTX MPCapableSYNACKRX ... MPTcpExt: 0 0 0 ...
Which would produce a mapping structure like:{ "TcpExt": {"SyncookiesSent":0, "SyncookiesRecv":4, "SyncookiesFailed":0, ... } "IpExt": {"InNoRoutes":55, "InTruncatedPkts":27786, "InMcastPkts":1435, ... } "MPTcpExt": {"MPCapableSYNACKRX":0, "MPCapableSYNTX":0, "MPCapableSYNACKRX":0, ... } }
- Parameters:
procFile
- the file to processkeys
- an optional array of keys to return in the outer map. If none are given, all found keys are returned.- Returns:
- a map of keys to stats
-
parseStatistics
Parses /proc files formatted as "statistic (long)value" to produce a simple mapping. An example would be /proc/net/snmp6. The file format would look like:Ip6InReceives 8026 Ip6InHdrErrors 0 Icmp6InMsgs 2 Icmp6InErrors 0 Icmp6OutMsgs 424 Udp6IgnoredMulti 5 Udp6MemErrors 1 UdpLite6InDatagrams 37 UdpLite6NoPorts 1
Which would produce a mapping structure like:{ "Ip6InReceives":8026, "Ip6InHdrErrors":0, "Icmp6InMsgs":2, "Icmp6InErrors":0, ... }
- Parameters:
procFile
- the file to processseparator
- a regex specifying the separator between statistic and value- Returns:
- a map of statistics and associated values
-
parseStatistics
OverloadedparseStatistics(String, Pattern)
using a whitespace separator.- Parameters:
procFile
- the file to process- Returns:
- a map of statistics and associated values
- See Also:
-