proc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Cpu        float64
	ReadBytes  uint64
	WriteBytes uint64
}

type FS

type FS struct {
	procfs.FS
	BootTime int64
}

func NewFS

func NewFS(mountPoint string) (*FS, error)

NewFS returns a new FS mounted under the given mountPoint. It will error if the mount point can't be read.

func (*FS) AllProcs

func (fs *FS) AllProcs() ProcIter

type GroupCountMap

type GroupCountMap map[string]GroupCounts

type GroupCounts added in v0.1.0

type GroupCounts struct {
	Counts
	Procs           int
	Memresident     uint64
	Memvirtual      uint64
	OldestStartTime time.Time
}

type Grouper

type Grouper struct {

	// track how much was seen last time so we can report the delta
	GroupStats map[string]Counts
	// contains filtered or unexported fields
}

func NewGrouper

func NewGrouper(trackChildren bool, namer common.MatchNamer) *Grouper

func (*Grouper) Groups

func (g *Grouper) Groups() GroupCountMap

Groups returns GroupCounts with Counts that never decrease in value from one call to the next. Even if processes exit, their CPU and IO contributions up to that point are included in the results. Even if no processes remain in a group it will still be included in the results.

func (*Grouper) Update

func (g *Grouper) Update(iter ProcIter) (int, error)

Update tracks any new procs that should be according to policy, and updates the metrics for already tracked procs. Permission errors are returned as a count, and will not affect the error return value.

type Memory

type Memory struct {
	Resident uint64
	Virtual  uint64
}

type Proc

type Proc interface {
	// GetPid() returns the POSIX PID (process id).  They may be reused over time.
	GetPid() int
	// GetProcId() returns (pid,starttime), which can be considered a unique process id.
	// It may fail if the caller doesn't have permission to read /proc/<pid>/stat, or if
	// the process has disapeared.
	GetProcId() (ProcId, error)
	// GetStatic() returns various details read from files under /proc/<pid>/.  Technically
	// name may not be static, but we'll pretend it is.
	// It may fail if the caller doesn't have permission to read those files, or if
	// the process has disapeared.
	GetStatic() (ProcStatic, error)
	// GetMetrics() returns various metrics read from files under /proc/<pid>/.
	// It may fail if the caller doesn't have permission to read those files, or if
	// the process has disapeared.
	GetMetrics() (ProcMetrics, error)
}

Proc wraps the details of the underlying procfs-reading library.

type ProcId

type ProcId struct {
	// UNIX process id
	Pid int
	// The time the process started after system boot, the value is expressed
	// in clock ticks.
	StartTimeRel uint64
}

ProcId uniquely identifies a process.

type ProcIdInfo

type ProcIdInfo struct {
	ProcId
	ProcStatic
	ProcMetrics
}

func Info

func Info(p Proc) (ProcIdInfo, error)

func (ProcIdInfo) GetMetrics

func (p ProcIdInfo) GetMetrics() (ProcMetrics, error)

func (ProcIdInfo) GetPid

func (p ProcIdInfo) GetPid() int

func (ProcIdInfo) GetProcId

func (p ProcIdInfo) GetProcId() (ProcId, error)

func (ProcIdInfo) GetStatic

func (p ProcIdInfo) GetStatic() (ProcStatic, error)

type ProcIdStatic

type ProcIdStatic struct {
	ProcId
	ProcStatic
}

type ProcInfo

type ProcInfo struct {
	ProcStatic
	ProcMetrics
}

type ProcIter

type ProcIter interface {
	// Next returns true if the iterator is not exhausted.
	Next() bool
	// Close releases any resources the iterator uses.
	Close() error
	// The iterator satisfies the Proc interface.
	Proc
}

ProcIter is an iterator over a sequence of procs.

type ProcMetrics

type ProcMetrics struct {
	CpuTime       float64
	ReadBytes     uint64
	WriteBytes    uint64
	ResidentBytes uint64
	VirtualBytes  uint64
}

ProcMetrics contains data read from /proc/pid/*

type ProcStatic

type ProcStatic struct {
	Name      string
	Cmdline   []string
	ParentPid int
	StartTime time.Time
}

ProcStatic contains data read from /proc/pid/*

type TrackedProc

type TrackedProc struct {

	// GroupName is an optional tag for this proc.
	GroupName string
	// contains filtered or unexported fields
}

TrackedProc accumulates metrics for a process, as well as remembering an optional GroupName tag associated with it.

func (*TrackedProc) GetCmdLine

func (tp *TrackedProc) GetCmdLine() []string

func (*TrackedProc) GetName

func (tp *TrackedProc) GetName() string

func (*TrackedProc) GetStats

func (tp *TrackedProc) GetStats() (aggregate, latest Counts, mem Memory, start time.Time)

type Tracker

type Tracker struct {
	// Tracked holds the processes are being monitored.  Processes
	// may be blacklisted such that they no longer get tracked by
	// setting their value in the Tracked map to nil.
	Tracked map[ProcId]*TrackedProc
	// ProcIds is a map from pid to ProcId.  This is a convenience
	// to allow finding the Tracked entry of a parent process.
	ProcIds map[int]ProcId
}

Tracker tracks processes and records metrics.

func NewTracker

func NewTracker() *Tracker

func (*Tracker) Ignore

func (t *Tracker) Ignore(id ProcId)

func (*Tracker) Track

func (t *Tracker) Track(groupName string, idinfo ProcIdInfo)

func (*Tracker) Update

func (t *Tracker) Update(procs ProcIter) ([]ProcIdInfo, int, error)

Scan procs and update metrics for those which are tracked. Processes that have gone away get removed from the Tracked map. New processes are returned, along with the count of permission errors.

Jump to

Keyboard shortcuts

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