sys_mon

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CpuFs

type CpuFs struct {
	CpuCount int
	CurrFreq []int64
	CpuList  []cpuFs
	// contains filtered or unexported fields
}

Structure to hold values retrieved from: '/sys/devices/system/cpu/cpufreq/policy*' directories

func CpuFsNew

func CpuFsNew() (*CpuFs, error)

func (*CpuFs) Close

func (cf *CpuFs) Close()

func (*CpuFs) CurrFreqUpdate

func (cf *CpuFs) CurrFreqUpdate() error

func (*CpuFs) ListUpdate

func (cf *CpuFs) ListUpdate() error

type CpuPercentPid

type CpuPercentPid struct {
	CpuPercent float32
	MemoryRss  int64
	// contains filtered or unexported fields
}

func CpuPercentPidNew

func CpuPercentPidNew(pid int) (*CpuPercentPid, error)

CpuPercentPidNew: Create and initialise 'C' structure.

func (*CpuPercentPid) Close

func (s *CpuPercentPid) Close()

Close: Freeing 'C' structure.

func (*CpuPercentPid) Update

func (v *CpuPercentPid) Update() error

update current values

type Diskstats

type Diskstats struct {
	Details []gdiskstats
	// contains filtered or unexported fields
}

func DiskstatsNew

func DiskstatsNew() (*Diskstats, error)

DiskstatsNew: Create and initialise 'C' structure.

func (*Diskstats) Close

func (s *Diskstats) Close()

Close: Freeing 'C' structure.

func (*Diskstats) Update

func (s *Diskstats) Update() error

Update: 'Diskstats' structure.

type MapHeader

type MapHeader struct {
	Start    uint32
	End      uint32
	Flags    string
	Offset   uint64
	DevMaj   uint32
	DevMin   uint32
	Inode    uint32
	Pathname string
	// contains filtered or unexported fields
}

func (*MapHeader) ToString

func (v *MapHeader) ToString() string

type Meminfo

type Meminfo struct {
	MemTotal          uint32
	MemFree           uint32
	MemAvailable      uint32
	Buffers           uint32
	Cached            uint32
	SwapCached        uint32
	Active            uint32
	Inactive          uint32
	ActiveAnon        uint32
	InactiveAnon      uint32
	ActiveFile        uint32
	InactiveFile      uint32
	Unevictable       uint32
	Mlocked           uint32
	SwapTotal         uint32
	SwapFree          uint32
	Dirty             uint32
	Writeback         uint32
	AnonPages         uint32
	Mapped            uint32
	Shmem             uint32
	Kreclaimable      uint32
	Slab              uint32
	Sreclaimable      uint32
	Sunreclaim        uint32
	KernelStack       uint32
	PageTables        uint32
	NfsUnstable       uint32
	Bounce            uint32
	WritebackTmp      uint32
	CommitLimit       uint32
	CommittedAs       uint32
	VmallocTotal      uint32
	VmallocUsed       uint32
	VmallocChunk      uint32
	Percpu            uint32
	HardwareCorrupted uint32
	AnonHugePages     uint32
	ShmemHugePages    uint32
	ShmemPmdMapped    uint32
	FileHugePages     uint32
	FilePmdMapped     uint32
	HugePagesTotal    uint32
	HugePagesFree     uint32
	HugePagesRsvd     uint32
	HugePagesSurp     uint32
	Hugepagesize      uint32
	Hugetlb           uint32
	DirectMap4k       uint32
	DirectMap2M       uint32
	DirectMap1G       uint32
	// contains filtered or unexported fields
}

func MeminfoNew

func MeminfoNew() (*Meminfo, error)

MeminfoNew: Create and initialise 'C' structure.

func (*Meminfo) Close

func (s *Meminfo) Close()

Close: Freeing 'C' structure.

func (*Meminfo) Update

func (s *Meminfo) Update() (*Meminfo, error)

Update: 'Meminfo' structure.

type NanoMeasureMethod

type NanoMeasureMethod C.int
const (
	// (0) Wall time (also known as clock time or wall-clock time) is simply
	// the total time elapsed during the measurement. It’s the time you
	// can measure with a stopwatch, assuming that you are able to start
	// and stop it exactly at the execution points you want.
	NANO_CLOCK_WALL NanoMeasureMethod = C.CLOCK_REALTIME
	// (2) CPU Time, on the other hand, refers to the time the CPU was busy
	// processing the program’s instructions. The time spent waiting for
	// other things to complete (like I/O operations) is not included in
	// the CPU time.
	NANO_CLOCK_CPUTIME NanoMeasureMethod = C.CLOCK_PROCESS_CPUTIME_ID
)

type Partitions

type Partitions struct {
	Details []partition
	// contains filtered or unexported fields
}

func PartitionsNew

func PartitionsNew() (*Partitions, error)

PartitionsNew: Create and initialise 'C' structure.

func (*Partitions) Close

func (s *Partitions) Close()

Close: Freeing 'C' structure.

func (*Partitions) Update

func (s *Partitions) Update() error

Update: 'Partitions' structure.

type PidInfos

type PidInfos struct {
	Details []storeFile
	// contains filtered or unexported fields
}

PidInfos: structure to store PID information for all processes.

func PidInfosNew

func PidInfosNew() (*PidInfos, error)

PidInfosNew: Create and initialise 'C' structure. No need to 'free' (close) anything, everything is already handled.

func (*PidInfos) GetPidFromFilename

func (sf *PidInfos) GetPidFromFilename(filename string) int

Get pid using the filename base. Returns "-1" if not found.

func (*PidInfos) GetPidFromName

func (sf *PidInfos) GetPidFromName(name string) int

Get pid using the name. Note: Instead of the previous, this function is based on a 'comm' field which contains only 16 bytes, which means that if the name is greater than 16 characters, it will be truncated. Returns "-1" if not found.

type ProcNetDev

type ProcNetDev struct {

	// Suffix, default: 'iB' !!! max char length = 15
	Suffix string
	// Unit, default: '/s' !!! max char length = 15
	Unit       string
	Interfaces []iface
	// contains filtered or unexported fields
}

func ProcNetDevNew

func ProcNetDevNew(pid ...uint32) (*ProcNetDev, error)

ProcNetDevNew: Create and initialize the "C" structure. If a "pid" is given, the statistics relate to the process. Otherwise, it's the overall flow

func (*ProcNetDev) Close

func (s *ProcNetDev) Close()

Close: Freeing 'C' structure.

func (*ProcNetDev) GetAvailableInterfaces

func (s *ProcNetDev) GetAvailableInterfaces() []string

Retrieve available network interfaces

func (*ProcNetDev) GetWanAdress

func (s *ProcNetDev) GetWanAdress(adress string, useStunSrv ...bool) (string, error)

GetWanAdress: Retrieve wan adress using http get method or using a 'stun' server whether 'useStunSrv' was toggled. http get: "ifconfig.co" stun srv: "stun1.l.google.com:19302"

func (*ProcNetDev) SetSuffix

func (s *ProcNetDev) SetSuffix(suffix string) error

SetSuffix:

func (*ProcNetDev) SetUnit

func (s *ProcNetDev) SetUnit(unit string) error

SetUnit:

func (*ProcNetDev) Update

func (s *ProcNetDev) Update() error

Update:

type ProcPidStat

type ProcPidStat struct {
	Pid                 uint
	Comm                string
	State               string
	Ppid                int
	Pgrp                int
	Session             int
	TtyNr               int
	Tpgid               int
	Flags               uint
	Minflt              uint32
	Cminflt             uint32
	Majflt              uint32
	Cmajflt             uint32
	Utime               uint32
	Stime               uint32
	Cutime              int32
	Cstime              int32
	Priority            int32
	Nice                int32
	NumThreads          int32
	Itrealvalue         int32
	Starttime           uint64
	Vsize               uint32
	Rss                 int32
	Rsslim              uint32
	Startcode           uint32
	Endcode             uint32
	Startstack          uint32
	Kstkesp             uint32
	Kstkeip             uint32
	Signal              uint32
	Blocked             uint32
	Sigignore           uint32
	Sigcatch            uint32
	Wchan               uint32
	Nswap               uint32
	Cnswap              uint32
	ExitSignal          int
	Processor           int
	RtPriority          uint
	Policy              uint
	DelayacctBlkioTicks uint64
	GuestTime           uint32
	CguestTime          int32
	StartData           uint32
	EndData             uint32
	StartBrk            uint32
	ArgStart            uint32
	ArgEnd              uint32
	EnvStart            uint32
	EnvEnd              uint32
	ExitCode            int
	// contains filtered or unexported fields
}

func ProcPidStatNew

func ProcPidStatNew(pid int) (*ProcPidStat, error)

ProcPidStatNew: Create and initialise 'C' structure.

func (*ProcPidStat) Close

func (s *ProcPidStat) Close()

Close: Freeing 'C' structure.

func (*ProcPidStat) Update

func (s *ProcPidStat) Update() error

Update: 'ProcPidStat' structure.

type Smaps

type Smaps struct {
	Rollup *smapsRollup

	Smaps []smap

	// Values are given as kB inside parsed files,
	// enable this flag to convert to Bytes
	ConvertToBytes bool
	// contains filtered or unexported fields
}
  • Structures functions, this section handle files like 'smaps', 'smaps_rollup',
  • 'maps' is not used here because information are contained inside 'smaps'
  • via 'Header' variable of 'Rollup' or 'Smaps' structures

Information 'man procfs' search '/smaps' then press 'n' until '/proc/[pid]/smaps'

func SmapsNew

func SmapsNew(pid int, maxReadEntries ...int) (*Smaps, error)

StatNew: Create a new structure that will contains required information about 'proc/[pid]/stat' files 'maxReadEntries' define the length of the buffer to read 'smaps' file, default is set to 2k.

func (*Smaps) Close

func (s *Smaps) Close()

Close: Freeing 'C' structure.

func (*Smaps) UpdateRollup

func (s *Smaps) UpdateRollup() error

Update: 'C' structure content with actual values.

func (*Smaps) UpdateSmaps

func (s *Smaps) UpdateSmaps() error

Update: 'C' structure content with actual values.

type StatusFile

type StatusFile struct {
	Name                     string
	Umask                    string
	State                    string
	Tgid                     uint
	Ngid                     uint
	Pid                      uint
	Ppid                     uint
	TracerPid                uint
	Uid                      *resfId
	Gid                      *resfId
	FdSize                   uint64
	Groups                   []uint
	NsTgid                   []uint
	NsPid                    []uint
	NsPgid                   []uint
	NsSid                    []uint
	Vm                       *statusFileVmem
	Threads                  int
	SigQ                     string
	SigPnd                   string
	ShdPnd                   string
	SigBlk                   string
	SigIgn                   string
	SigCgt                   string
	CapInh                   string
	CapPrm                   string
	CapEff                   string
	CapBnd                   string
	CapAmb                   string
	NoNewPrivs               int
	Seccomp                  int
	StoreBypass              string
	CpusAllowed              string
	CpusAllowedList          string
	MemsAllowed              string
	MemsAllowedList          string
	VoluntaryCtxtSwitches    uint64
	NonvoluntaryCtxtSwitches uint64
	// contains filtered or unexported fields
}

func StatusFileNew

func StatusFileNew(pid int) (*StatusFile, error)

StatusFileNew: create and initialize the "C" structure. No need to 'free' (close) anything, everything is already handled.

type SysTherm

type SysTherm struct {
	Interfaces []sysTherm
	// contains filtered or unexported fields
}

Structure to hold Thermal information retrieved from: '/sys/class/hwmon/hwmon*' directories. Note: "n/a", "-0°C" or "-1" value means not available data.

func SysThermNew

func SysThermNew() (*SysTherm, error)

func (*SysTherm) Close

func (st *SysTherm) Close()

Close: and free memory used for structure storage

func (*SysTherm) Update

func (st *SysTherm) Update() error

Update: 'Interfaces' data

type TimeSpent

type TimeSpent struct {
	Spent              float64
	NANO_CLOCK_WALL    NanoMeasureMethod
	NANO_CLOCK_CPUTIME NanoMeasureMethod
	SC_CLK_TCK         int64
	// contains filtered or unexported fields
}

func TimeSpentNew

func TimeSpentNew(method ...NanoMeasureMethod) (*TimeSpent, error)

TimeSpentNew: Create and initialise 'C' structure. if argument is set to -1, the default value is 'NANO_CLOCK_WALL'

func (*TimeSpent) Close

func (s *TimeSpent) Close()

Close: Freeing 'C' structure.

func (*TimeSpent) MesurementMethodGet

func (s *TimeSpent) MesurementMethodGet() int

GetMesurementMethod:

func (*TimeSpent) MesurementMethodSet

func (s *TimeSpent) MesurementMethodSet(method NanoMeasureMethod)

SetMesurementMethod:

func (*TimeSpent) NanoCalculate

func (s *TimeSpent) NanoCalculate() float64

NanoCalculate: calculate the nanoseconds between 2 measurement periods

func (*TimeSpent) NanoGet

func (s *TimeSpent) NanoGet()

NanoGet: get current nano count measurement depend on defined 'method' argument 'NANO_CLOCK_WALL' or 'NANO_CLOCK_CPUTIME' Value is internally stored.

func (*TimeSpent) SpentGet

func (s *TimeSpent) SpentGet() float64

GetSpent: time previously calculated.

func (*TimeSpent) TicksCalculate

func (s *TimeSpent) TicksCalculate() float64

TicksCalculate: calculate tick between 2 tick periods

func (*TimeSpent) TicksGet

func (s *TimeSpent) TicksGet()

TicksGet: get current ticks count. Value is internally stored.

Jump to

Keyboard shortcuts

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