statgo

package module
v0.0.0-...-3ae2cda Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2017 License: MIT Imports: 6 Imported by: 6

README

wercker status

StatGo

StatGo give you access to OS metrics like network interface bandwith, cpus usage ...
It supports FreeBSD, Linux, OSX & more, it's in fact a libstatgrab binding for Golang.
Tested on FreeBSD, OSX, Linux amd64, Linux arm.

Compilation

You need at least libstatgrab 0.91, Debian & Ubuntu only have 0.90 ...

On Debian/Ubunt & OSX, you can simply install libstatgrab with the usual commands:

./configure --prefix=/usr/local
make
sudo make install

You may have to set CGO_LDFLAGS and CGO_CFLAGS environment according to your path:

export CGO_CFLAGS=-I/usr/local/include
export CGO_LDFLAGS=-L/usr/local/lib

Note: On OSX you need to install gcc to access cgo.

go get github.com/akhenakh/statgo
Usage
s := NewStat()
s.HostInfos()
OSName: Darwin
OSRelease:  14.4.0
OSVersion:  Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64
Platform:   x86_64
HostName:   kamoulox
NCPUs:      4
MaxCPUs:    4
BitWidth:   64

s.CPUStats()
User:       7.500000
Kernel:     2.500000
Idle:       90.000000
IOWait      0.000000
Swap:       0.000000
Nice:       0.000000
LoadMin1:   2.206055
LoadMin5:   2.031250
LoadMin15:  1.970703

s.FSInfos()[0]
DeviceName:         /dev/disk1
FSType:             hfs
MountPoint:         /
Size:               249769230336
Used:               224367140864
Free:               25402089472
Available:          25139945472
TotalInodes:        60978814
UsedInodes:         54841132
FreeInodes:         6137682
AvailableInodes:    6137682

s.InterfaceInfos()[0]
Name:   en2
Speed:  0
Factor: 1000000
Duplex: Full Duplex
State:  UP

s.MemStats()
Total:      16649420800
Free:       4323848192
Used:       12325572608
Cache:      0
SwapTotal:  3221225472
SwapUsed:   2528378880
SwapFree:   692846592

s.NetIOStats()
IntName:    en0
TX:         2310272606
RX:         3336240203
IPackets:   114473581
OPackets:   129430304
IErrors:    0
OErrors:    0
Collisions: 0

s.ProcessStats()
Total:      343
Running:    335
Sleeping:   0
Stopped:    0
Zombie:     8

s.PagesStats()
PageIn:     90173695
PageOut:    90173695
Status
  • Host infos
  • cpu stats
  • load average
  • network interfaces infos
  • mem stats
  • swap stat
  • io stats
  • net io stats
  • process count
  • page stats
Contributors

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUStats

type CPUStats struct {
	User   float64
	Kernel float64
	Idle   float64
	IOWait float64
	Swap   float64
	Nice   float64

	// System load averages
	LoadMin1  float64
	LoadMin5  float64
	LoadMin15 float64

	// The time taken in seconds since the last call of the function
	Period time.Duration

	TimeTaken time.Time
}

CPUStats contains cpu stats Delivers correlated relative cpu counters (where total is 100%)

func (*CPUStats) String

func (c *CPUStats) String() string

type DiskIOStats

type DiskIOStats struct {
	DiskName   string
	ReadBytes  int
	WriteBytes int

	// The time period over which read_bytes and write_bytes were transferred.
	Period time.Duration

	TimeTaken time.Time
}

DiskIOStats contains disk io stats Expressed in bytes

func (*DiskIOStats) String

func (d *DiskIOStats) String() string

type FSInfos

type FSInfos struct {
	DeviceName string
	FSType     string
	MountPoint string

	// Size, Used, Free, Available are expressed in bytes
	Size      int
	Used      int
	Free      int
	Available int

	// Inodes count
	TotalInodes     int
	UsedInodes      int
	FreeInodes      int
	AvailableInodes int
}

FSInfos contains filesystem & mountpoints informations

func (*FSInfos) String

func (fs *FSInfos) String() string

type HostInfos

type HostInfos struct {
	OSName    string
	OSRelease string
	OSVersion string
	Platform  string
	HostName  string
	NCPUs     int
	MaxCPUs   int
	BitWidth  int //32, 64 bits
	// contains filtered or unexported fields
}

HostInfos contains informations related to the system

func (*HostInfos) String

func (h *HostInfos) String() string

type InterfaceDuplexType

type InterfaceDuplexType int

InterfaceDuplexType network interface duplex type

const (
	InterfaceFullDuplex InterfaceDuplexType = iota
	InterfaceHalfDuplex
	InterfaceUnknownDuplex
)

func (InterfaceDuplexType) MarshalText

func (s InterfaceDuplexType) MarshalText() ([]byte, error)

func (InterfaceDuplexType) String

func (s InterfaceDuplexType) String() string

func (*InterfaceDuplexType) UnmarshalText

func (s *InterfaceDuplexType) UnmarshalText(text []byte) error

type InterfaceInfos

type InterfaceInfos struct {
	Name string
	// Speed in factor/sec
	Speed  int
	Factor int
	Duplex InterfaceDuplexType
	State  InterfaceState
}

InterfaceInfos network interface related infos

func (*InterfaceInfos) String

func (i *InterfaceInfos) String() string

type InterfaceState

type InterfaceState int

InterfaceState up or down

const (
	InterfaceUpState InterfaceState = iota
	InterfaceDownState
)

func (InterfaceState) MarshalText

func (s InterfaceState) MarshalText() ([]byte, error)

func (InterfaceState) String

func (s InterfaceState) String() string

func (*InterfaceState) UnmarshalText

func (s *InterfaceState) UnmarshalText(text []byte) error

type MemStats

type MemStats struct {
	// The total amount of real memory in bytes
	Total int

	// Theount of real memory in bytes.
	Free int

	// The used amount of real memory in bytes
	Used int

	// The amount of real memory in bytes used for caching
	Cache int

	// The total swap space in bytes.
	SwapTotal int

	// The used swap in bytes
	SwapUsed int

	// The free swap in bytes
	SwapFree int
}

MemStats contains memory & swap stats expressed in bytes

func (*MemStats) String

func (m *MemStats) String() string

type NetIOStats

type NetIOStats struct {
	IntName string

	// Number of bytes transmitted
	TX int

	// Number of bytes received
	RX int

	// Number of packets received
	IPackets int

	// Number of packets transmitted
	OPackets int

	// Number of receive errors
	IErrors int

	// Number of transmit errors
	OErrors int

	// Number of collisions count
	Collisions int

	// the time period over which tx and rx were transferred
	Period time.Duration

	TimeTaken time.Time
}

NetIOStats contains network interfaces stats

func (*NetIOStats) String

func (n *NetIOStats) String() string

type PageStats

type PageStats struct {
	// The number of pages swapped into memory.
	PageIn int

	// The number of pages swapped out of memory (to swap).
	PageOut int

	// The time period over which pages_pagein and pages_pageout weretransferred.
	Period time.Duration

	TimeTaken time.Time
}

PageStats contains pages stats

func (*PageStats) String

func (p *PageStats) String() string

type ProcessStats

type ProcessStats struct {
	// The total number of processes
	Total int

	// The number of running processes
	Running int

	// The number of sleeping processes
	Sleeping int

	// The number of stopped processes
	Stopped int

	// The number of zombie processes
	Zombie int
}

ProcessStats contains processes count stats

func (*ProcessStats) String

func (p *ProcessStats) String() string

type Stat

type Stat struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Stat handle to access libstatgrab

func NewStat

func NewStat() *Stat

NewStat return a new Stat handle

func (*Stat) CPUStats

func (s *Stat) CPUStats() *CPUStats

CPUStats get cpu related stats note that 1st call to 100ms may return NaN as values Go equivalent to sg_cpu_percents

func (*Stat) DiskIOStats

func (s *Stat) DiskIOStats() []*DiskIOStats

DiskIOStats get I/Os related stats note that 1st call to 100ms may return NaN as values Go equivalent to sg_disk_io_stats

func (*Stat) FSInfos

func (s *Stat) FSInfos() []*FSInfos

FSInfos return an FSInfo struct per mounted filesystem Go equivalent to sg_get_fs_stats

func (*Stat) HostInfos

func (s *Stat) HostInfos() *HostInfos

HostInfos get the host informations Go equivalent to sg_host_info

func (*Stat) InteraceInfos

func (s *Stat) InteraceInfos() []*InterfaceInfos

func (*Stat) MemStats

func (s *Stat) MemStats() *MemStats

MemStats get memory & swap related stats Go equivalent to sg_get_mem_stats & sg_get_swap_stats

func (*Stat) NetIOStats

func (s *Stat) NetIOStats() []*NetIOStats

NetIOStats get interface ios related stats Go equivalent to sg_get_network_io_stats

func (*Stat) PageStats

func (s *Stat) PageStats() *PageStats

PageStats get pages related stats Go equivalent to sg_get_page_stats_diff

func (*Stat) ProcessStats

func (s *Stat) ProcessStats() *ProcessStats

ProcessStats get prceosses related stats note that 1st call to 100ms may return NaN as values Go equivalent to sg_cpu_percents

Jump to

Keyboard shortcuts

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