gosigar

package module
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

Go sigar Build Status Build status

Overview

Go sigar is a golang implementation of the sigar API. The Go version of sigar has a very similar interface, but is being written from scratch in pure go/cgo, rather than cgo bindings for libsigar.

Test drive

$ go get github.com/elastic/gosigar
$ cd $GOPATH/src/github.com/elastic/gosigar/examples/ps
$ go build
$ ./ps

Supported platforms

The features vary by operating system.

Feature Linux Darwin Windows OpenBSD FreeBSD
Cpu X X X X X
CpuList X X X X
FDUsage X X
FileSystemList X X X X X
FileSystemUsage X X X X X
HugeTLBPages X
LoadAverage X X X X
Mem X X X X X
ProcArgs X X X X
ProcEnv X X X
ProcExe X X X
ProcFDUsage X X
ProcList X X X X
ProcMem X X X X
ProcState X X X X
ProcTime X X X X
Rusage X X
Swap X X X X
Uptime X X X X

OS Specific Notes

FreeBSD

Mount both linprocfs and procfs for compatability. Consider adding these mounts to your /etc/fstab file so they are mounted automatically at boot.

sudo mount -t procfs proc /proc
sudo mkdir -p /compat/linux/proc
sudo mount -t linprocfs /dev/null /compat/linux/proc

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	// RunStateSleep corresponds to a sleep state
	RunStateSleep = 'S'
	// RunStateRun corresponds to a running state
	RunStateRun = 'R'
	// RunStateStop corresponds to a stopped state
	RunStateStop = 'T'
	// RunStateZombie marks a zombie process
	RunStateZombie = 'Z'
	// RunStateIdle corresponds to an idle state
	RunStateIdle = 'D'
	// RunStateUnknown corresponds to a process in an unknown state
	RunStateUnknown = '?'
)

Variables

View Source
var Procd string

Functions

func FormatPercent

func FormatPercent(percent float64) string

func FormatSize

func FormatSize(size uint64) string

Go version of apr_strfsize

func IsNotImplemented

func IsNotImplemented(err error) bool

IsNotImplemented returns true if the error is ErrNotImplemented

Types

type ConcreteSigar

type ConcreteSigar struct{}

func (*ConcreteSigar) CollectCpuStats

func (c *ConcreteSigar) CollectCpuStats(collectionInterval time.Duration) (<-chan Cpu, chan<- struct{})

func (*ConcreteSigar) GetFDUsage

func (c *ConcreteSigar) GetFDUsage() (FDUsage, error)

func (*ConcreteSigar) GetFileSystemUsage

func (c *ConcreteSigar) GetFileSystemUsage(path string) (FileSystemUsage, error)

func (*ConcreteSigar) GetHugeTLBPages added in v0.9.0

func (c *ConcreteSigar) GetHugeTLBPages() (HugeTLBPages, error)

func (*ConcreteSigar) GetLoadAverage

func (c *ConcreteSigar) GetLoadAverage() (LoadAverage, error)

func (*ConcreteSigar) GetMem

func (c *ConcreteSigar) GetMem() (Mem, error)

func (*ConcreteSigar) GetRusage added in v0.8.0

func (c *ConcreteSigar) GetRusage(who int) (Rusage, error)

GetRusage return the resource usage of the process Possible params: 0 = RUSAGE_SELF, 1 = RUSAGE_CHILDREN, 2 = RUSAGE_THREAD

func (*ConcreteSigar) GetSwap

func (c *ConcreteSigar) GetSwap() (Swap, error)

type Cpu

type Cpu struct {
	User    uint64
	Nice    uint64
	Sys     uint64
	Idle    uint64
	Wait    uint64
	Irq     uint64
	SoftIrq uint64
	Stolen  uint64
}

Cpu contains CPU time stats

func (Cpu) Delta

func (cpu Cpu) Delta(other Cpu) Cpu

Delta returns the difference between two Cpu stat objects

func (*Cpu) Get

func (self *Cpu) Get() error

func (*Cpu) Total

func (cpu *Cpu) Total() uint64

Total returns total CPU time

type CpuList

type CpuList struct {
	List []Cpu
}

CpuList contains a list of CPUs on the host system

func (*CpuList) Get

func (self *CpuList) Get() error

type ErrNotImplemented

type ErrNotImplemented struct {
	OS string
}

ErrNotImplemented is returned when a particular statistic isn't implemented on the host OS.

func (ErrNotImplemented) Error

func (e ErrNotImplemented) Error() string

type FDUsage

type FDUsage struct {
	Open   uint64
	Unused uint64
	Max    uint64
}

FDUsage contains stats on filesystem usage

func (*FDUsage) Get

func (self *FDUsage) Get() error

type FileSystem

type FileSystem struct {
	DirName     string
	DevName     string
	TypeName    string
	SysTypeName string
	Options     string
	Flags       uint32
}

FileSystem contains basic information about a given mounted filesystem

type FileSystemList

type FileSystemList struct {
	List []FileSystem
}

FileSystemList gets a list of mounted filesystems

func (*FileSystemList) Get

func (self *FileSystemList) Get() error

type FileSystemUsage

type FileSystemUsage struct {
	Total     uint64
	Used      uint64
	Free      uint64
	Avail     uint64
	Files     uint64
	FreeFiles uint64
}

FileSystemUsage contains basic stats for the specified filesystem

func (*FileSystemUsage) Get

func (self *FileSystemUsage) Get(path string) error

func (*FileSystemUsage) UsePercent

func (self *FileSystemUsage) UsePercent() float64

type HugeTLBPages added in v0.9.0

type HugeTLBPages struct {
	Total              uint64
	Free               uint64
	Reserved           uint64
	Surplus            uint64
	DefaultSize        uint64
	TotalAllocatedSize uint64
}

HugeTLBPages contains HugePages stats

func (*HugeTLBPages) Get added in v0.9.0

func (self *HugeTLBPages) Get() error

type LoadAverage

type LoadAverage struct {
	One, Five, Fifteen float64
}

LoadAverage reports standard load averages

func (*LoadAverage) Get

func (self *LoadAverage) Get() error

type Mem

type Mem struct {
	Total      uint64
	Used       uint64
	Free       uint64
	ActualFree uint64
	ActualUsed uint64
}

Mem contains host memory stats

func (*Mem) Get

func (self *Mem) Get() error

type ProcArgs

type ProcArgs struct {
	List []string
}

ProcArgs contains a list of args for a specified process

func (*ProcArgs) Get

func (self *ProcArgs) Get(pid int) error

type ProcEnv

type ProcEnv struct {
	Vars map[string]string
}

ProcEnv contains a map of environment variables for specified process

func (*ProcEnv) Get

func (self *ProcEnv) Get(pid int) error

type ProcExe

type ProcExe struct {
	Name string
	Cwd  string
	Root string
}

ProcExe contains basic data about a specified process

func (*ProcExe) Get

func (self *ProcExe) Get(pid int) error

type ProcFDUsage

type ProcFDUsage struct {
	Open      uint64
	SoftLimit uint64
	HardLimit uint64
}

ProcFDUsage contains data on file limits and usage

func (*ProcFDUsage) Get

func (self *ProcFDUsage) Get(pid int) error

type ProcList

type ProcList struct {
	List []int
}

ProcList contains a list of processes found on the host system

func (*ProcList) Get

func (self *ProcList) Get() error

type ProcMem

type ProcMem struct {
	Size        uint64
	Resident    uint64
	Share       uint64
	MinorFaults uint64
	MajorFaults uint64
	PageFaults  uint64
}

ProcMem contains memory statistics for a specified process

func (*ProcMem) Get

func (self *ProcMem) Get(pid int) error

type ProcState

type ProcState struct {
	Name      string
	Username  string
	State     RunState
	Ppid      int
	Pgid      int
	Tty       int
	Priority  int
	Nice      int
	Processor int
}

ProcState contains basic metadata and process ownership info for the specified process

func (*ProcState) Get

func (self *ProcState) Get(pid int) error

type ProcTime

type ProcTime struct {
	StartTime uint64
	User      uint64
	Sys       uint64
	Total     uint64
}

ProcTime contains run time statistics for a specified process

func (*ProcTime) FormatStartTime

func (self *ProcTime) FormatStartTime() string

func (*ProcTime) FormatTotal

func (self *ProcTime) FormatTotal() string

func (*ProcTime) Get

func (self *ProcTime) Get(pid int) error

type RunState

type RunState byte

RunState is a byte-long code used to specify the current runtime state of a process

type Rusage added in v0.8.0

type Rusage struct {
	Utime    time.Duration
	Stime    time.Duration
	Maxrss   int64
	Ixrss    int64
	Idrss    int64
	Isrss    int64
	Minflt   int64
	Majflt   int64
	Nswap    int64
	Inblock  int64
	Oublock  int64
	Msgsnd   int64
	Msgrcv   int64
	Nsignals int64
	Nvcsw    int64
	Nivcsw   int64
}

Rusage contains data on resource usage for a specified process

func (*Rusage) Get added in v0.8.0

func (r *Rusage) Get(who int) error

type Sigar

type Sigar interface {
	CollectCpuStats(collectionInterval time.Duration) (<-chan Cpu, chan<- struct{})
	GetLoadAverage() (LoadAverage, error)
	GetMem() (Mem, error)
	GetSwap() (Swap, error)
	GetHugeTLBPages(HugeTLBPages, error)
	GetFileSystemUsage(string) (FileSystemUsage, error)
	GetFDUsage() (FDUsage, error)
	GetRusage(who int) (Rusage, error)
}

Sigar is an interface for gathering system host stats

type Swap

type Swap struct {
	Total uint64
	Used  uint64
	Free  uint64
}

Swap contains stats on swap space

func (*Swap) Get

func (self *Swap) Get() error

type Uptime

type Uptime struct {
	Length float64
}

Uptime reports system uptime

func (*Uptime) Format

func (self *Uptime) Format() string

func (*Uptime) Get

func (self *Uptime) Get() error

Directories

Path Synopsis
Package cgroup reads metrics and other tunable parameters associated with control groups, a Linux kernel feature for grouping tasks to track and limit resource usage.
Package cgroup reads metrics and other tunable parameters associated with control groups, a Linux kernel feature for grouping tasks to track and limit resource usage.
examples
df
ps
ss
Go interface to the Linux netlink process connector.
Go interface to the Linux netlink process connector.
sys
windows
Package windows contains various Windows system call.
Package windows contains various Windows system call.

Jump to

Keyboard shortcuts

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