Documentation
¶
Overview ¶
data from /proc/stat about the entire system This data appears to be updated somewhat frequently
Index ¶
- Constants
- Variables
- func GetPidList(list *Pidlist, maxProcsToScan int)
- func ParsePidList(s string) ([]int, error)
- func ParseUserList(s string) ([]int, error)
- func ProcStatsReader(pids Pidlist, filter Filters, cur *ProcSampleList, infoMap ProcInfoMap)
- func ProcStatsRecord(interval uint32, curList, prevList ProcSampleList, ...)
- func ReadFileLines(filename string) ([]string, error)
- func ReadFloat(str string) float64
- func ReadInt(str string) int64
- func ReadSmallFile(filename string) ([]byte, error)
- func ReadSmallFileStat(filename string) ([]byte, os.FileInfo, error)
- func ReadUInt(str string) uint64
- func SafeSub(a, b uint64) uint64
- func SafeSubFloat(a, b float64) float64
- func ScaledSub(cur, prev uint64, scale float64) uint64
- func StripSpecial(r rune) rune
- func SystemStatsReader(cur *SystemStats) error
- func SystemStatsReaderFromLines(cur *SystemStats, lines []string) error
- func TaskStatsLookupPid(conn *NLConn, sample *ProcSample) error
- func TaskStatsReader(conn *NLConn, pids Pidlist, cur *ProcSampleList)
- func TaskStatsRecord(interval uint32, curList, prevList ProcSampleList, ...)
- func UpdateProcStatsHist(histMap ProcStatsHistMap, deltaMap ProcSampleMap)
- func UpdateSysStatsHist(hist *SystemStatsHist, delta *SystemStats)
- func UpdateTaskStatsHist(histMap TaskStatsHistMap, deltaMap ProcSampleMap)
- type Filters
- type NLConn
- type Pidlist
- type ProcInfo
- type ProcInfoMap
- type ProcSample
- type ProcSampleList
- type ProcSampleMap
- type ProcStats
- type ProcStatsHist
- type ProcStatsHistMap
- type ProcStatsMap
- type ProcStatsSeekReader
- type SystemStats
- type SystemStatsHist
- type SystemStatsSeekReader
- type TaskStats
- type TaskStatsHist
- type TaskStatsHistMap
- type TaskStatsMap
Constants ¶
const ( CTRL_ATTR_FAMILY_ID = 1 CTRL_ATTR_FAMILY_NAME = 2 CTRL_CMD_GETFAMILY = 3 )
On older Linux systems, including linux/genetlink.h and taskstats.h doesn't compile. To fix this, we define these three symbols here. Note that they just happen to be sequential, but they are from 3 different enums.
Variables ¶
var StatsPath = "/proc/stat"
make this a package var so tests or users can change it
Functions ¶
func GetPidList ¶
We churn the pidlist constantly, so this is an optimization to reuse the underlying list every time. Replace the new values in the old list, shrinking or growing as necessary. This saves a bit of GC. Note that reading /proc to get the pidlist returns the elements in a consistent order. If we ever get a new source of a pidlist like perf_events or something, make sure it sorts.
func ParsePidList ¶
ParsePidList take a string of process ids and converts it into a list of int pids
func ParseUserList ¶
ParseUsrList take a string of Unix usernames and converts it into a slice of int userids
func ProcStatsReader ¶
func ProcStatsReader(pids Pidlist, filter Filters, cur *ProcSampleList, infoMap ProcInfoMap)
ProcStatsReader reads and parses /proc/[pid]/stat for all of pids
func ProcStatsRecord ¶
func ProcStatsRecord(interval uint32, curList, prevList ProcSampleList, sumMap, deltaMap ProcSampleMap)
ProcStatsRecord computes the delta between the Proc elements of two ProcSampleLists These lists do not need to have exactly the same processes in it, but they must both be sorted by Pid. This generally works out because reading the pids from /proc puts them in a consistent order. If we ever get a new source of the pidlist, perf_events or whatever, make sure it sorts.
func ReadFileLines ¶
Read a small file and split on newline
func ReadSmallFile ¶
ReadSmallFile is like os.ReadFile but dangerously optimized for reading files from /proc. The file is not statted first, and the same buffer is used every time.
func ReadSmallFileStat ¶
ReadSmallFileStat is like ReadSmallFile except it also returns a FileInfo from os.Stat
func SafeSub ¶
crude protection against rollover. This will miss the last portion of the previous sample before the overflow, but capturing that is complicated because of the various number types involved and their inconsistent documentation.
func SafeSubFloat ¶
func StripSpecial ¶
remove grouping characters that confuse the termui parser
func SystemStatsReader ¶
func SystemStatsReader(cur *SystemStats) error
func SystemStatsReaderFromLines ¶
func SystemStatsReaderFromLines(cur *SystemStats, lines []string) error
func TaskStatsLookupPid ¶
func TaskStatsLookupPid(conn *NLConn, sample *ProcSample) error
func TaskStatsReader ¶
func TaskStatsReader(conn *NLConn, pids Pidlist, cur *ProcSampleList)
TaskStatsReader uses conn to build a TaskStatsMap for all pids.
func TaskStatsRecord ¶
func TaskStatsRecord(interval uint32, curList, prevList ProcSampleList, sumMap, deltaMap ProcSampleMap)
TaskStatsRecord computes the delta between Task elements of two ProcSampleLists These lists do not need to have exactly the same processes in it, but they must both be sorted by Pid. This generally works out because reading the pids from /proc puts them in a consistent order. If we ever get a new source of the pidlist, perf_events or whatever, make sure it sorts.
func UpdateProcStatsHist ¶
func UpdateProcStatsHist(histMap ProcStatsHistMap, deltaMap ProcSampleMap)
func UpdateSysStatsHist ¶
func UpdateSysStatsHist(hist *SystemStatsHist, delta *SystemStats)
func UpdateTaskStatsHist ¶
func UpdateTaskStatsHist(histMap TaskStatsHistMap, deltaMap ProcSampleMap)
Types ¶
type Filters ¶
func FiltersInit ¶
type NLConn ¶
type NLConn struct {
// contains filtered or unexported fields
}
NLConn holds the context necessary to pass around to external callers
type ProcInfo ¶
type ProcInfo struct {
FirstSeen time.Time
LastSeen time.Time
Comm string // short name from /proc/pid/stat
Cmdline []string // raw parts from /proc/pid/cmdline
Friendly string // our magically transformed name
Pid uint64
Ppid uint64
Pgrp int64
Session int64
Ttynr int64
Tpgid int64
Flags uint64
Starttime uint64
Nice int64
Rtpriority uint64
Policy uint64
UID uint32
}
ProcInfo holds properties of a process that don't change very often or can't change
type ProcInfoMap ¶
func (ProcInfoMap) MaybePrune ¶
func (m ProcInfoMap) MaybePrune(chance float64, pids Pidlist, expiry time.Duration)
type ProcSample ¶
type ProcSampleList ¶
type ProcSampleList struct {
Samples []ProcSample
Len uint32
}
func NewProcSampleList ¶
func NewProcSampleList(size int) ProcSampleList
type ProcSampleMap ¶
type ProcSampleMap map[int]*ProcSample
type ProcStats ¶
type ProcStats struct {
CaptureTime time.Time
Utime uint64
Stime uint64
Cutime uint64
Cstime uint64
Numthreads uint64
Rss uint64
Guesttime uint64
Cguesttime uint64
}
ProcStats holds the fast changing data that comes back from /proc/[pid]/stat These fields are documented in the linux proc(5) man page There are many more of these fields that don't change very often. These are stored in the Cmdline struct.
type ProcStatsHist ¶
type ProcStatsHist struct {
Utime *hdrhistogram.Histogram
Stime *hdrhistogram.Histogram
Ustime *hdrhistogram.Histogram // utime + stime
Cutime *hdrhistogram.Histogram
Cstime *hdrhistogram.Histogram
Custime *hdrhistogram.Histogram // cutime + cstime
}
These are somewhat expensive to track, so only maintain a hist for ones we use
func NewProcStatsHist ¶
func NewProcStatsHist() *ProcStatsHist
type ProcStatsHistMap ¶
type ProcStatsHistMap map[int]*ProcStatsHist
type ProcStatsMap ¶
type ProcStatsSeekReader ¶
type ProcStatsSeekReader struct {
PID int
// contains filtered or unexported fields
}
func (*ProcStatsSeekReader) Close ¶
func (reader *ProcStatsSeekReader) Close() error
func (*ProcStatsSeekReader) Initialize ¶
func (reader *ProcStatsSeekReader) Initialize() error
func (*ProcStatsSeekReader) ReadStats ¶
func (reader *ProcStatsSeekReader) ReadStats(cur *ProcStats) error
type SystemStats ¶
type SystemStats struct {
CaptureTime time.Time
Usr uint64
Nice uint64
Sys uint64
Idle uint64
Iowait uint64
Irq uint64
Softirq uint64
Steal uint64
Guest uint64
GuestNice uint64
Ctxt uint64
ProcsTotal uint64
ProcsRunning uint64
ProcsBlocked uint64
}
func SystemStatsRecord ¶
func SystemStatsRecord(interval uint32, cur, prev, sum *SystemStats) *SystemStats
type SystemStatsHist ¶
type SystemStatsHist struct {
Usr *hdrhistogram.Histogram
Nice *hdrhistogram.Histogram
Sys *hdrhistogram.Histogram
Idle *hdrhistogram.Histogram
Iowait *hdrhistogram.Histogram
ProcsTotal *hdrhistogram.Histogram
ProcsRunning *hdrhistogram.Histogram
ProcsBlocked *hdrhistogram.Histogram
}
func NewSysStatsHist ¶
func NewSysStatsHist() *SystemStatsHist
type SystemStatsSeekReader ¶
type SystemStatsSeekReader struct {
// contains filtered or unexported fields
}
func (*SystemStatsSeekReader) Close ¶
func (reader *SystemStatsSeekReader) Close() error
func (*SystemStatsSeekReader) Initialize ¶
func (reader *SystemStatsSeekReader) Initialize() error
func (*SystemStatsSeekReader) ReadStats ¶
func (reader *SystemStatsSeekReader) ReadStats(cur *SystemStats) error
type TaskStats ¶
type TaskStats struct {
Capturetime time.Time
Cpudelaycount uint64 // delay count waiting for CPU, while runnable
Cpudelaytotal uint64 // delay time waiting for CPU, while runnable, in ns
Blkiodelaycount uint64 // delay count waiting for disk
Blkiodelaytotal uint64 // delay time waiting for disk
Swapindelaycount uint64 // delay count waiting for swap
Swapindelaytotal uint64 // delay time waiting for swap
Nvcsw uint64 // voluntary context switches
Nivcsw uint64 // involuntary context switches
Freepagesdelaycount uint64 // delay count waiting for memory reclaim
Freepagesdelaytotal uint64 // delay time waiting for memory reclaim in unknown units
}
TaskStats is the set of data from linux/taskstats.h that seemed relevant and accurate. There are other things in the kernel struct that are not tracked here, but perhaps should be.
type TaskStatsHist ¶
type TaskStatsHist struct {
Cpudelay *hdrhistogram.Histogram
Iowait *hdrhistogram.Histogram
Swap *hdrhistogram.Histogram
}
func NewTaskStatsHist ¶
func NewTaskStatsHist() *TaskStatsHist
type TaskStatsHistMap ¶
type TaskStatsHistMap map[int]*TaskStatsHist
type TaskStatsMap ¶
TaskStatsMap maps pid to TaskStats, suually representing a sample of all pids