Documentation
¶
Overview ¶
Package sysmon reads host resource figures for bentoo-tray: memory from /proc/meminfo, pressure stall information from /proc/pressure, free disk space and running emerge processes. It returns data and wrapped errors only; it never logs and applies no thresholds, which are the caller's policy.
Index ¶
Constants ¶
const ( DefaultEmergeMaxRead = 4 << 20 DefaultEmergeMaxLine = 64 << 10 )
Default bounds of an EmergeFollower read.
Variables ¶
var ErrNoPressure = errors.New("pressure stall information unavailable")
ErrNoPressure reports that the kernel exposes no pressure stall information file for a resource. The error returned with it also wraps the underlying fs.ErrNotExist; a pressure file that exists but fails to read or parse is a different error.
Functions ¶
This section is empty.
Types ¶
type Disk ¶
type Disk struct {
Path string // the watched path as configured
Dev uint64 // st_dev of Path, the key that tells filesystems apart
Size, Free uint64 // bytes; Free = Bavail * Bsize
}
Disk is the space of the filesystem holding a watched path.
type EmergeEvent ¶
type EmergeEvent struct {
Kind EmergeEventKind
Atom string
Status int
}
EmergeEvent is one recognised emerge.log line. Atom is set for Started and Completed ("category/package-version"), Status for ExitFailed.
func ParseEmergeLine ¶
func ParseEmergeLine(line []byte) (EmergeEvent, bool)
ParseEmergeLine reads one emerge.log line, without its newline. ok is false for every line that is not one of the four events, including an event line whose atom is not a plain category/package-version.
type EmergeEventKind ¶
type EmergeEventKind int
EmergeEventKind is what one emerge.log line reports.
const ( EmergeStarted EmergeEventKind = iota + 1 // ">>> emerge (i of n) <atom> to <root>" EmergeCompleted // "::: completed emerge (i of n) <atom> to <root>" EmergeExitOK // "*** exiting successfully." EmergeExitFailed // "*** exiting unsuccessfully with status '<n>'." )
The emerge.log events a failed-build check needs.
type EmergeFollower ¶
type EmergeFollower struct {
Path string
MaxRead int
MaxLine int
// contains filtered or unexported fields
}
EmergeFollower reads the lines appended to an emerge log since Start. It survives rotation by truncation (the size drops below the offset) and by replacement (the inode changes): either restarts at the new beginning. MaxRead bounds the bytes one Read consumes and MaxLine the length of a line; a longer line is discarded whole. Zero bounds take the defaults. It returns errors and never logs; it is not safe for concurrent use.
func (*EmergeFollower) Read ¶
func (f *EmergeFollower) Read() ([]EmergeEvent, error)
Read returns the events of the complete lines appended since the last Read, in order. A follower whose Start failed starts now, at the end of the log, and returns no event, so lines written before the log became readable are never reported. A log that cannot be read is an error naming the path; when it comes back as a new file it is read from its beginning.
func (*EmergeFollower) Start ¶
func (f *EmergeFollower) Start() error
Start positions the follower at the current end of the log, so only lines appended afterwards are read.
type Memory ¶
type Memory struct {
Total, Available, SwapTotal, SwapFree uint64
}
Memory is a /proc/meminfo reading, every field in bytes.
func ParseMeminfo ¶
ParseMeminfo reads MemTotal, MemAvailable, SwapTotal and SwapFree from the text of /proc/meminfo. Keys are matched whole, so SwapCached or MemFree is never read in place of a wanted key. MemTotal and MemAvailable are required: a missing MemAvailable is an error, never a fallback to MemFree. The swap keys read as zero when absent.
type Mount ¶
type Mount struct {
Point string // the mount point, unescaped
Source string // the mounted device or pseudo source, unescaped
FSType string
ReadOnly bool // `ro` in the per-mount options or in the superblock options
}
Mount is one line of the kernel mount table.
func ParseMountinfo ¶
ParseMountinfo parses a mountinfo table (proc(5)). The fields after the variable-length optional list are found from its " - " separator, never by position. A malformed line makes the whole parse an error naming its line number, so a caller never mistakes a shortened table for unmounted filesystems.
type Pressure ¶
Pressure is the avg60 figures of a /proc/pressure file. HasFull reports whether the file carried a full line at all, so an all-zero full line is told apart from an absent one.
func ParsePressure ¶
ParsePressure reads the avg60 figures of a /proc/pressure file. The some and full lines are told apart by their first word and avg60 is found by its key, never by position. The some line is required; the full line is optional (older kernels expose none for cpu) and sets HasFull when present.
type Reader ¶
Reader reads host figures under Root ("/" in production, a testdata tree in tests). Statfs defaults to syscall.Statfs when nil; tests inject a fake.
func (Reader) Disk ¶
Disk reports the size and the unprivileged free space of the filesystem holding path. Free counts Bavail, not Bfree: the reserved blocks Bfree includes belong to root. Dev is the path's st_dev rather than the statfs Fsid, which several filesystems report as zero. A block size that is not positive is an error rather than a nonsense figure.
func (Reader) EmergeRunning ¶
EmergeRunning reports whether any process under Root/proc runs emerge, judged from its cmdline (comm reads python3 for the python-exec wrapper). A process whose cmdline cannot be read, typically because it exited during the scan, is skipped; failing to list Root/proc itself is an error.