sigar

package module
v0.0.0-...-a501fde Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

README

Go sigar

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/cloudfoundry/gosigar
$ cd $GOPATH/src/github.com/cloudfoundry/gosigar/examples
$ go run uptime.go

Supported platforms

Feature Linux Darwin Windows
CPU yes yes yes
Memory yes yes yes
Swap yes yes yes
Load Avg yes yes no
FS Usage yes yes yes
Disk IO yes no yes
Uptime yes yes no
Process yes yes no

License

Apache 2.0

Documentation

Index

Constants

View Source
const (
	ConnProtoUdp = NetConnProto(iota + 1)
	ConnProtoTcp
	ConnProtoRaw
)
View Source
const (
	ConnStateEstablished = NetConnState(iota + 1)
	ConnStateSynSent
	ConnStateSynRecv
	ConnStateFinWait1
	ConnStateFinWait2
	ConnStateTimeWait
	ConnStateClose
	ConnStateCloseWait
	ConnStateLastAck
	ConnStateListen
	ConnStateClosing
)
View Source
const (
	RunStateSleep   = 'S'
	RunStateRun     = 'R'
	RunStateStop    = 'T'
	RunStateZombie  = 'Z'
	RunStateIdle    = 'D'
	RunStateUnknown = '?'
)

Variables

View Source
var ErrNotImplemented error = errors.New("Collection not implemented for this operating system")
View Source
var Etcd string
View Source
var Procd string
View Source
var Sysd string

Functions

func FormatPercent

func FormatPercent(percent float64) string

func FormatSize

func FormatSize(size uint64) string

Go version of apr_strfsize

func LoadStartTime

func LoadStartTime()

func ReadConnIp

func ReadConnIp(field string, lenBytes int) (net.IP, uint64, error)

Decode an IP:port pair, with either a 16 or 4-byte address and 2-byte port,

both hex-encoded. TODO: Test on a big-endian architecture.

func ReadUint

func ReadUint(val string) uint64

Convert the value to an uint64, ignoring any error

Types

type ConcreteSigar

type ConcreteSigar struct{}

func (*ConcreteSigar) CollectCpuStats

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

func (*ConcreteSigar) GetFileSystemUsage

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

func (*ConcreteSigar) GetLoadAverage

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

func (*ConcreteSigar) GetMem

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

func (*ConcreteSigar) GetSwap

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

func (*ConcreteSigar) GetSystemInfo

func (c *ConcreteSigar) GetSystemInfo() (SystemInfo, error)

type Cpu

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

func (Cpu) Delta

func (cpu Cpu) Delta(other Cpu) Cpu

func (*Cpu) Get

func (self *Cpu) Get() error

func (*Cpu) Total

func (cpu *Cpu) Total() uint64

type CpuList

type CpuList struct {
	List []Cpu
}

func (*CpuList) Get

func (self *CpuList) Get() error

type DiskIo

type DiskIo struct {
	ReadOps     uint64
	ReadBytes   uint64
	ReadTimeMs  uint64
	WriteOps    uint64
	WriteBytes  uint64
	WriteTimeMs uint64
	IoTimeMs    uint64
}

func (DiskIo) Delta

func (self DiskIo) Delta(other DiskIo) DiskIo

type DiskList

type DiskList struct {
	List map[string]DiskIo
}

func (*DiskList) Get

func (self *DiskList) Get() error

type FileSystem

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

type FileSystemList

type FileSystemList struct {
	List []FileSystem
}

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
}

func (*FileSystemUsage) Get

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

func (*FileSystemUsage) UsePercent

func (self *FileSystemUsage) UsePercent() float64

type Getter

type Getter interface {
	Get() error
}

Simple Get() that returns an error

type ICMPStats

type ICMPStats struct {
	InMsgs          uint64
	InErrors        uint64
	InDestUnreachs  uint64
	OutMsgs         uint64
	OutErrors       uint64 // Not reported by snmp6
	OutDestUnreachs uint64
}

type IPStats

type IPStats struct {
	InReceives      uint64
	InHdrErrors     uint64
	InAddrErrors    uint64
	ForwDatagrams   uint64
	InDelivers      uint64
	InDiscards      uint64
	InUnknownProtos uint64
	OutRequests     uint64
	OutDiscards     uint64
	OutNoRoutes     uint64
}

type LoadAverage

type LoadAverage struct {
	One, Five, Fifteen float64
}

func (*LoadAverage) Get

func (self *LoadAverage) Get() error

type Mem

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

func (*Mem) Get

func (self *Mem) Get() error

type NetConn

type NetConn struct {
	LocalAddr   net.IP
	RemoteAddr  net.IP
	LocalPort   uint64
	RemotePort  uint64
	SendQueue   uint64
	RecvQueue   uint64
	Status      NetConnState
	Proto       NetConnProto
	Inode       uint64
	Pid         int
	ProcessName string
}

func (NetConn) String

func (self NetConn) String() string

type NetConnProto

type NetConnProto int

func (NetConnProto) String

func (self NetConnProto) String() string

type NetConnState

type NetConnState int

func (NetConnState) String

func (self NetConnState) String() string

type NetIface

type NetIface struct {
	Name       string
	MTU        uint64
	Mac        string
	LinkStatus string

	SendBytes      uint64
	RecvBytes      uint64
	SendPackets    uint64
	RecvPackets    uint64
	SendCompressed uint64
	RecvCompressed uint64
	RecvMulticast  uint64

	SendErrors     uint64
	RecvErrors     uint64
	SendDropped    uint64
	RecvDropped    uint64
	SendFifoErrors uint64
	RecvFifoErrors uint64

	RecvFramingErrors uint64
	SendCarrier       uint64
	SendCollisions    uint64
}

type NetIfaceList

type NetIfaceList struct {
	List []NetIface
}

func (*NetIfaceList) Get

func (self *NetIfaceList) Get() error

type NetProtoV4Stats

type NetProtoV4Stats struct {
	IP   IPStats
	ICMP ICMPStats
	TCP  TCPStats
	UDP  UDPStats
}

func (*NetProtoV4Stats) Get

func (self *NetProtoV4Stats) Get() error

type NetProtoV6Stats

type NetProtoV6Stats struct {
	IP   IPStats
	ICMP ICMPStats
	TCP  TCPStats
	UDP  UDPStats
}

func (*NetProtoV6Stats) Get

func (self *NetProtoV6Stats) Get() error

type NetRawConnList

type NetRawConnList struct {
	List []NetConn
}

func (*NetRawConnList) Get

func (self *NetRawConnList) Get() error

type NetRawV6ConnList

type NetRawV6ConnList struct {
	List []NetConn
}

func (*NetRawV6ConnList) Get

func (self *NetRawV6ConnList) Get() error

type NetTcpConnList

type NetTcpConnList struct {
	List []NetConn
}

func (*NetTcpConnList) Get

func (self *NetTcpConnList) Get() error

type NetTcpV6ConnList

type NetTcpV6ConnList struct {
	List []NetConn
}

func (*NetTcpV6ConnList) Get

func (self *NetTcpV6ConnList) Get() error

type NetUdpConnList

type NetUdpConnList struct {
	List []NetConn
}

func (*NetUdpConnList) Get

func (self *NetUdpConnList) Get() error

type NetUdpV6ConnList

type NetUdpV6ConnList struct {
	List []NetConn
}

func (*NetUdpV6ConnList) Get

func (self *NetUdpV6ConnList) Get() error

type ProcArgs

type ProcArgs struct {
	List []string
}

func (*ProcArgs) Get

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

type ProcExe

type ProcExe struct {
	Name string
	Cwd  string
	Root string
}

func (*ProcExe) Get

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

type ProcIo

type ProcIo struct {
	ReadBytes  uint64
	WriteBytes uint64
	ReadOps    uint64
	WriteOps   uint64
}

func (*ProcIo) Get

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

type ProcList

type ProcList struct {
	List []int
}

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
	PageFileBytes uint64 // Currently only collected on Windows
}

func (*ProcMem) Get

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

type ProcState

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

func (*ProcState) Get

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

type ProcTime

type ProcTime struct {
	CollectionTime time.Time
	StartTime      uint64 // Milliseconds since epoch
	User           uint64 // User time in milliseconds
	Sys            uint64 // System time in milliseconds
	Total          uint64 // Total time in milliseconds

	// Not valid until after CalculateCpuPercent()
	PercentUserTime  uint64
	PercentSysTime   uint64
	PercentTotalTime uint64
}

func (*ProcTime) CalculateCpuPercent

func (self *ProcTime) CalculateCpuPercent(other *ProcTime) error

Calculate percent of CPU usage by diffing counters. The "other" ProcTime should be from an earlier reading.

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 Process

type Process struct {
	ProcState
	ProcIo
	ProcMem
	ProcTime
	ProcArgs
	ProcExe
}

type ProcessList

type ProcessList struct {
	List []Process
}

func (*ProcessList) Get

func (self *ProcessList) Get() error

type RunState

type RunState byte

type Sigar

type Sigar interface {
	CollectCpuStats(collectionInterval time.Duration) (<-chan Cpu, chan<- struct{})
	GetLoadAverage() (LoadAverage, error)
	GetMem() (Mem, error)
	GetSwap() (Swap, error)
	GetFileSystemUsage(string) (FileSystemUsage, error)
	GetSystemInfo() (SystemInfo, error)
	GetSystemDistribution() (SystemDistribution, error)
}

type Swap

type Swap struct {
	Total uint64
	Used  uint64
	Free  uint64
}

func (*Swap) Get

func (self *Swap) Get() error

type SystemDistribution

type SystemDistribution struct {
	Description string
}

func (*SystemDistribution) Get

func (self *SystemDistribution) Get() error

type SystemInfo

type SystemInfo struct {
	Sysname    string
	Nodename   string
	Release    string
	Version    string
	Machine    string
	Domainname string
}

func (*SystemInfo) Get

func (self *SystemInfo) Get() error

type TCPStats

type TCPStats struct {
	ActiveOpens  uint64
	PassiveOpens uint64
	AttemptFails uint64
	EstabResets  uint64
	CurrEstab    uint64 // Instantaneous value of currently established connections
	InSegs       uint64
	OutSegs      uint64
	RetransSegs  uint64
	InErrs       uint64
	OutRsts      uint64
}

type UDPStats

type UDPStats struct {
	InDatagrams  uint64
	OutDatagrams uint64
	InErrors     uint64
	NoPorts      uint64
	RcvbufErrors uint64 // Not reported by snmp6
	SndbufErrors uint64 // Not reported by snmp6
}

type Uptime

type Uptime struct {
	Length float64
}

func (*Uptime) Format

func (self *Uptime) Format() string

func (*Uptime) Get

func (self *Uptime) Get() error

Directories

Path Synopsis
examples
df command
free command
ps command
uptime command
Go interface to the Linux netlink process connector.
Go interface to the Linux netlink process connector.

Jump to

Keyboard shortcuts

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