Documentation ¶
Overview ¶
Package pidstat implements metrics collection per-PID like memory/cpu
Index ¶
- type PerProcessStat
- func (s *PerProcessStat) CPUUsage() float64
- func (s *PerProcessStat) Cgroup(subsys string) string
- func (s *PerProcessStat) Cmdline() string
- func (s *PerProcessStat) Comm() string
- func (s *PerProcessStat) Egid() (string, error)
- func (s *PerProcessStat) Euid() (string, error)
- func (s *PerProcessStat) IOUsage() float64
- func (s *PerProcessStat) MemUsage() float64
- func (s *PerProcessStat) Pid() string
- func (s *PerProcessStat) Reset(p string)
- func (s *PerProcessStat) User() string
- type PerProcessStatInterface
- type PerProcessStatMetrics
- type PidFilterFunc
- type ProcessStat
- func (c *ProcessStat) ByCPUUsage() []*PerProcessStat
- func (s *ProcessStat) ByIOUsage() []*PerProcessStat
- func (c *ProcessStat) ByMemUsage() []*PerProcessStat
- func (s *ProcessStat) CPUUsagePerCgroup(cgroup string) float64
- func (s *ProcessStat) Collect()
- func (s *ProcessStat) MemUsagePerCgroup(cgroup string) float64
- func (s *ProcessStat) SetPidFilter(filter PidFilterFunc)
- type ProcessStatInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PerProcessStat ¶
type PerProcessStat struct { Metrics *PerProcessStatMetrics // contains filtered or unexported fields }
PerProcessStat represents per process statistics and methods.
func NewPerProcessStat ¶
func NewPerProcessStat(m *metrics.MetricContext, p string) *PerProcessStat
NewPerProcessStat registers with metriccontext for single process
func (*PerProcessStat) CPUUsage ¶
func (s *PerProcessStat) CPUUsage() float64
CPUUsage returns amount of work done by this process in kernel/user Unit: # of logical CPUs
func (*PerProcessStat) Cgroup ¶
func (s *PerProcessStat) Cgroup(subsys string) string
Cgroup returns the name of the cgroup for this process for the input cgroup subsystem
func (*PerProcessStat) Cmdline ¶
func (s *PerProcessStat) Cmdline() string
Cmdline returns the complete command line used to invoke this process
func (*PerProcessStat) Comm ¶
func (s *PerProcessStat) Comm() string
Comm returns the command used to run for this process
func (*PerProcessStat) Egid ¶
func (s *PerProcessStat) Egid() (string, error)
Egid returns the effective gid for this process
func (*PerProcessStat) Euid ¶
func (s *PerProcessStat) Euid() (string, error)
Euid returns the effective uid for this process
func (*PerProcessStat) IOUsage ¶
func (s *PerProcessStat) IOUsage() float64
IOUsage returns cumulative bytes read/written by this process (bytes/sec)
func (*PerProcessStat) MemUsage ¶
func (s *PerProcessStat) MemUsage() float64
MemUsage returns amount of memory resident for this process in bytes.
func (*PerProcessStat) Pid ¶
func (s *PerProcessStat) Pid() string
Pid returns the pid for this process
func (*PerProcessStat) Reset ¶
func (s *PerProcessStat) Reset(p string)
Reset initializes all usage counters to zeros and the instance can be reused.
func (*PerProcessStat) User ¶
func (s *PerProcessStat) User() string
User returns the username for the process - looked up by effective uid
type PerProcessStatInterface ¶
PerProcessStatInterface defines common methods that all platform specific PerProcessStat types must implement
type PerProcessStatMetrics ¶
type PerProcessStatMetrics struct { Pid string Utime *metrics.Counter Stime *metrics.Counter Rss *metrics.Gauge IOReadBytes *metrics.Counter IOWriteBytes *metrics.Counter // contains filtered or unexported fields }
PerProcessStatMetrics represents metrics for the per process stats collection
func NewPerProcessStatMetrics ¶
func NewPerProcessStatMetrics(m *metrics.MetricContext, pid string) *PerProcessStatMetrics
NewPerProcessStatMetrics registers with metricscontext
func (*PerProcessStatMetrics) Collect ¶
func (s *PerProcessStatMetrics) Collect()
Collect collects per process CPU/Memory/IO metrics
func (*PerProcessStatMetrics) Register ¶
func (s *PerProcessStatMetrics) Register()
Register metrics with metric context
func (*PerProcessStatMetrics) Reset ¶
func (s *PerProcessStatMetrics) Reset(pid string)
Reset resets all counters and gauges to original values
func (*PerProcessStatMetrics) Unregister ¶
func (s *PerProcessStatMetrics) Unregister()
Unregister metrics with metriccontext
type PidFilterFunc ¶
type PidFilterFunc func(pidstat *PerProcessStat) (interested bool)
PidFilterFunc represents a function that can be passed to PerProcessStat to express interest in tracking a particular process
func (PidFilterFunc) Filter ¶
func (f PidFilterFunc) Filter(pidstat *PerProcessStat) (interested bool)
Filter runs the user supplied filter function
type ProcessStat ¶
type ProcessStat struct { Processes map[string]*PerProcessStat // contains filtered or unexported fields }
ProcessStat represents per-process cpu usage statistics
func NewProcessStat ¶
func NewProcessStat(m *metrics.MetricContext, Step time.Duration) *ProcessStat
NewProcessStat registers with metriccontext and collects per-process cpu statistics every Step TODO: Implement better heuristics to manage load
- Collect metrics for newer processes at faster rate
- Slower rate for processes with negligible rate?
func (*ProcessStat) ByCPUUsage ¶
func (c *ProcessStat) ByCPUUsage() []*PerProcessStat
ByCPUUsage returns an slice of *PerProcessStat entries sorted by CPU usage
func (*ProcessStat) ByIOUsage ¶
func (s *ProcessStat) ByIOUsage() []*PerProcessStat
ByIOUsage returns an slice of *PerProcessStat entries sorted by Memory usage
func (*ProcessStat) ByMemUsage ¶
func (c *ProcessStat) ByMemUsage() []*PerProcessStat
ByMemUsage returns an slice of *PerProcessStat entries sorted by Memory usage
func (*ProcessStat) CPUUsagePerCgroup ¶
func (s *ProcessStat) CPUUsagePerCgroup(cgroup string) float64
CPUUsagePerCgroup returns cumulative CPU usage by cgroup
func (*ProcessStat) Collect ¶
func (s *ProcessStat) Collect()
Collect walks through /proc and updates stats Collect is usually called internally based on parameters passed via metric context
func (*ProcessStat) MemUsagePerCgroup ¶
func (s *ProcessStat) MemUsagePerCgroup(cgroup string) float64
MemUsagePerCgroup returns cumulative Memory usage by cgroup
func (*ProcessStat) SetPidFilter ¶
func (s *ProcessStat) SetPidFilter(filter PidFilterFunc)
SetPidFilter takes a PidFilterFunc and applies it as a filter to reduce number of processes to keep track of.
type ProcessStatInterface ¶
type ProcessStatInterface interface { ByCPUUsage() []*PerProcessStat ByMemUsage() []*PerProcessStat SetPidFilter(PidFilterFunc) }
ProcessStatInterface defines common methods that all platform specific ProcessStat type must implement