proc

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2021 License: MIT Imports: 11 Imported by: 4

README

goproc

Go Reference

Various Go utilities for using data from the Linux /proc pseudo-filesystem.

The APIs are still in flux, but should be usable.

Documentation

Overview

Package proc scrapes information from the /proc pseudo-filesystem on Linux.

The functions do a minimal amount of parsing before returning the data. See `man proc` and other documentation indicated by the API functions for more information on how to use them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadAverages

func LoadAverages() ([3]float64, error)

LoadAverages returns the 1, 5, and 15 minute load averages as reported by /proc/loadavg.

func MemInfo

func MemInfo() (map[string]uint64, error)

MemInfo returns the memory information fields from /proc/meminfo, such as "MemTotal" and "MemFree". Byte values are returned in bytes, not kB.

func NetDevStats

func NetDevStats() (receive, transmit map[string]map[string]uint64, err error)

NetDevStats returns the data in /proc/net/dev. Example: eth0 -> bytes -> 12345

func NetProtoStats

func NetProtoStats() (map[string]map[string]int64, error)

NetProtoStats parses the files /proc/net/netstat, and /proc/net/snmp. It returns the table of values as a 2-dimensional array from category -> key -> value. For example:

{
  "Tcp": {
    "ActiveOpens": 11023,
    "PassiveOpens": 64,
    ...
  },
 "Udp": {...},
 ...
}

Types

type CPUStatInfo

type CPUStatInfo struct {
	User       uint64
	Nice       uint64
	System     uint64
	Idle       uint64
	Iowait     uint64
	Irq        uint64
	Softirq    uint64
	Steal      uint64
	Guest      uint64
	Guest_nice uint64
}

A CPUStatInfo is a CPU entry in /proc/stat. All values are in USER_HZ.

type FSTabEntry

type FSTabEntry struct {
	Spec    string   // /dev/sda1
	File    string   // /mnt/data
	Vfstype string   // ext4
	Mntops  []string // [rw, relatime]
	Freq    int      // 0
	Passno  int      // 0
}

FSTabEntry describes a line from /proc/mounts, which is the fstab format. See 'man fstab' for the meaning of these fields. The field comments are examples of what might be found there (but see the man page for details).

func Mounts

func Mounts() ([]*FSTabEntry, error)

Read mount information from /proc/mounts for the current process. BUG(caleb): This doesn't handle spaces in mount points, even though fstab specifies an encoding for them.

type IOStatEntry

type IOStatEntry struct {
	// Partition info
	Major int
	Minor int
	Name  string
	// The rest of the fields are described in Linux's Documentation/iostats.txt.
	ReadsCompleted   uint64
	ReadsMerged      uint64
	SectorsRead      uint64
	ReadMillis       uint64
	WritesCompleted  uint64
	WritesMerged     uint64
	SectorsWritten   uint64
	WriteMillis      uint64
	NumInProgressIOs uint64
	IOMillis         uint64
	WeightedIOMillis uint64
}

IOStatEntry represents a line in /proc/diskstats.

func DiskStats

func DiskStats() ([]*IOStatEntry, error)

DiskStats reports disk information from /proc/diskstats.

type StatInfo

type StatInfo struct {
	Cpu           *CPUStatInfo
	Cpus          []*CPUStatInfo
	Intr          []uint64
	Ctxt          uint64
	Btime         time.Time
	Processes     uint64
	Procs_running uint64
	Procs_blocked uint64
}

StatInfo represents entries in /proc/stat.

func Stat

func Stat() (*StatInfo, error)

Stat returns kernel and CPU statistics as reported by /proc/stat.

Notes

Bugs

  • This doesn't handle spaces in mount points, even though fstab specifies an encoding for them.

Directories

Path Synopsis
nwstat module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL