Documentation ¶
Overview ¶
Package system provides various helper functions and types to interact with system information
Index ¶
- func CountProcessFileDescriptors(procPath string, pid int) (int, error)
- func CountProcessesFileDescriptors(procPath string, pids []int) (uint64, bool)
- func GetDefaultGateway(procPath string) (net.IP, error)
- func GetFileInode(path string) (uint64, error)
- func GetProcessNamespaceInode(procPath string, pid string, namespace string) (uint64, error)
- func GetProcessNetDevInode(procPath string, pid int) (uint64, error)
- func HostCPUCount() int
- func IsLocalAddress(address string) (string, error)
- func IsProcessHostNetwork(procPath string, netDevInode uint64) *bool
- func IsProcessHostUTSNamespace(_ string, namespaceID uint64) *bool
- func ParseProcessIPs(procPath string, pid int, filterFunc func(string) bool) ([]string, error)
- type NetworkRoute
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountProcessFileDescriptors ¶
CountProcessFileDescriptors gets the number of open file descriptors for a given pid
func CountProcessesFileDescriptors ¶
CountProcessesFileDescriptors returns the sum of open file descriptors for all given PIDs. Failed PIDs are silently skipped. A boolean is returned to indicate whether all PIDs failed or not.
func GetDefaultGateway ¶
GetDefaultGateway parses /proc/net/route and extract the first route with Destination == "00000000"
func GetFileInode ¶ added in v0.57.0
GetFileInode returns the inode number of a file
func GetProcessNamespaceInode ¶
GetProcessNamespaceInode performs a stat() call on /proc/<pid>/ns/<namespace> When targeting PID different than self, requires CAP_SYS_PTRACE to be able to read /proc/<pid>/ns/<namespace> in the first place
func GetProcessNetDevInode ¶ added in v0.57.0
GetProcessNetDevInode returns the inode of /proc/<pid>/net/dev
func HostCPUCount ¶
func HostCPUCount() int
HostCPUCount returns the number of logical CPUs from host
func IsLocalAddress ¶
IsLocalAddress returns the given address if it is local or an error if it is not
func IsProcessHostNetwork ¶
IsProcessHostNetwork returns true if the process is using the host network by checking if /proc/<pid>/net/dev has the same inode as /proc/1/net/dev
func IsProcessHostUTSNamespace ¶
IsProcessHostUTSNamespace compares namespaceID with known, harcoded host PID Namespace inode Keeps same signature as `IsProcessHostNetwork` as we may need to change implementation depending on Kernel evolution
func ParseProcessIPs ¶
ParseProcessIPs parses /proc/<pid>/net/fib_trie and returns the /32 IP addresses found. The result does not contain duplicate IPs.
Here's an example of /proc/<pid>/net/fib_trie that shows its format:
Main: +-- 0.0.0.0/1 2 0 2 +-- 0.0.0.0/4 2 0 2 |-- 0.0.0.0 /0 universe UNICAST +-- 10.4.0.0/24 2 1 2 |-- 10.4.0.0 /32 link BROADCAST /24 link UNICAST +-- 10.4.0.192/26 2 0 2 |-- 10.4.0.216 /32 host LOCAL |-- 10.4.0.255 /32 link BROADCAST +-- 127.0.0.0/8 2 0 2 +-- 127.0.0.0/31 1 0 0 |-- 127.0.0.0 /32 link BROADCAST /8 host LOCAL |-- 127.0.0.1 /32 host LOCAL |-- 127.255.255.255 /32 link BROADCAST Local: +-- 0.0.0.0/1 2 0 2 +-- 0.0.0.0/4 2 0 2 |-- 0.0.0.0 /0 universe UNICAST +-- 10.4.0.0/24 2 1 2 |-- 10.4.0.0 /32 link BROADCAST /24 link UNICAST +-- 10.4.0.192/26 2 0 2 |-- 10.4.0.216 /32 host LOCAL |-- 10.4.0.255 /32 link BROADCAST +-- 127.0.0.0/8 2 0 2 +-- 127.0.0.0/31 1 0 0 |-- 127.0.0.0 /32 link BROADCAST /8 host LOCAL |-- 127.0.0.1 /32 host LOCAL |-- 127.255.255.255 /32 link BROADCAST
The IPs that we're interested in are the ones that appear above lines that contain "/32 host".
Types ¶
type NetworkRoute ¶
NetworkRoute holds one network destination subnet and it's linked interface name
func ParseProcessRoutes ¶
func ParseProcessRoutes(procPath string, pid int) ([]NetworkRoute, error)
ParseProcessRoutes parses /proc/<pid>/net/route into a list of NetworkDestionation If PID is 0, it parses /proc/net/route instead