Documentation
¶
Overview ¶
Package sysstat reads what a Linux host and the current process are using: CPU (with the parts lost to softirq, steal and I/O wait), memory and swap, connection tracking, sockets, the NIC's link speed, and the process's own CPU, memory, threads and file descriptors. The node agent reports it with every stats batch; the panel shows its own.
The parsers here are pure and build everywhere, so they are tested on any OS. The readers (read.go) take a /proc and /sys root so tests can point them at a fixture; on a system without /proc they return zeros, which callers treat as "not known".
Index ¶
- func Clamp100(f float64) float64
- func DiskUsage(path string) (total, used uint64)
- func ParseOpenFilesLimit(s string) uint64
- func ParseStatusRSS(s string) uint64
- func ParseUint(s string) (uint64, bool)
- type CPUShare
- type CPUTimes
- type GoRuntime
- type Host
- type HostSampler
- type Mem
- type ProcSampler
- type ProcStat
- type Process
- type Reader
- type Sockets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiskUsage ¶
DiskUsage is the size and the used bytes of the file system holding path (0, 0 when it cannot be read).
func ParseOpenFilesLimit ¶
ParseOpenFilesLimit reads the soft "Max open files" from /proc/<pid>/limits (0 = unknown or unlimited).
func ParseStatusRSS ¶
ParseStatusRSS reads VmRSS from /proc/<pid>/status, in bytes.
Types ¶
type CPUShare ¶
CPUShare is how the whole machine's CPU time was spent between two samples, in percent of all CPUs.
type CPUTimes ¶
type CPUTimes struct {
Total, Idle, IOWait, Softirq, Steal uint64
}
CPUTimes is the aggregate "cpu" line of /proc/stat, in USER_HZ ticks summed over all CPUs: user nice system idle iowait irq softirq steal [guest guest_nice]. guest time is already inside user, so it is not added to Total.
type GoRuntime ¶
type GoRuntime struct {
Goroutines uint64
// HeapBytes is memory in live and not yet swept heap objects; TotalBytes is all memory the runtime mapped from the OS
// (heap, stacks, its own metadata), which is close to what the process costs beyond its binary.
HeapBytes, TotalBytes uint64
}
GoRuntime is what the Go runtime of this process holds.
func ReadGoRuntime ¶
func ReadGoRuntime() GoRuntime
ReadGoRuntime reads the runtime's own counters without stopping the world.
type Host ¶
type Host struct {
CPU CPUShare
Load1 float64
Mem Mem
// Connection tracking: entries and limit (0, 0 = not loaded).
ConntrackCount, ConntrackMax uint64
Sockets Sockets
}
Host is one sample of the machine.
type HostSampler ¶
type HostSampler struct {
R Reader
// contains filtered or unexported fields
}
HostSampler takes Host samples; CPU shares are over the time since the previous Sample (zero on the first). Safe for concurrent use.
type Mem ¶
type Mem struct {
Total, Avail, SwapTotal, SwapFree uint64
}
Mem is /proc/meminfo's totals in bytes (0 when missing).
func ParseMeminfo ¶
ParseMeminfo reads MemTotal, MemAvailable, SwapTotal and SwapFree.
type ProcSampler ¶
ProcSampler samples one process (PID "self" when empty). Safe for concurrent use.
func (*ProcSampler) Sample ¶
func (p *ProcSampler) Sample() Process
Sample reads the process now; CPUPct is over the time since the previous Sample (zero on the first).
type ProcStat ¶
type ProcStat struct {
// CPUTicks is utime plus stime, in USER_HZ ticks: the same unit as CPUTimes, so the two can be divided.
CPUTicks uint64
Threads uint32
}
ProcStat is what /proc/<pid>/stat says about a process.
func ParseProcStat ¶
ParseProcStat reads /proc/<pid>/stat. The command name (field 2) is in parentheses and may hold spaces and ")", so the fields are counted after the last ")".
type Process ¶
type Process struct {
// CPUPct is the process's CPU time over the interval in percent of the whole machine (all CPUs), so it can be set
// against the host's Busy: 25 on a 4-CPU machine is one CPU fully used.
CPUPct float64
RSS uint64
Threads uint32
// Open file descriptors (sockets are among them) and the soft limit (0 = not known).
FDs, FDLimit uint64
}
Process is one sample of a process.
type Reader ¶
type Reader struct {
Proc, Sys string
}
Reader reads under a /proc and a /sys root. The zero value reads the real ones.
func (Reader) Conntrack ¶
Conntrack returns the connection-tracking table's entries and its limit (0, 0 where netfilter's conntrack is not loaded). When the table is full the kernel drops new connections ("nf_conntrack: table full, dropping packet"), which looks to people like a node that stopped answering.
func (Reader) NICSpeedMbps ¶
NICSpeedMbps is the link speed of an interface in Mbit/s, 0 when the driver does not say (most virtual NICs).
type Sockets ¶
type Sockets struct {
// TCP sockets in use (established and listening), in TIME_WAIT, and orphaned (closed by the program, not yet by the peer).
TCP, TCPTimeWait, TCPOrphan uint32
UDP uint32
}
Sockets are the counts of /proc/net/sockstat and sockstat6 added together.
func ParseSockstat ¶
ParseSockstat reads "TCP: inuse N orphan N tw N ..." and "UDP: inuse N ..." (sockstat), or "TCP6: inuse N" and "UDP6: inuse N" (sockstat6). Call it on each file and Add the results.