systemmonitor

package module
v0.0.0-...-9407a13 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 13 Imported by: 2

README

systemmonitor Quickstart Guide


systemmonitor是go语言编写的“系统资源监视器”,监视的资源包括:系统信息、CPU使用、内存使用、网络、硬盘IO、主板温度

用法可以参考这个简单的web项目

注意: 目前只支持linux

how to run example


$ go get -u -v github.com/lambda-zhang/systemmonitor
$ cd $GOPATH/src/github.com/lambda-zhang/systemmonitor
$ go run example/test_monitor.go
###############################################
os:
	StartTime=2019-02-16 08:46:40 +0800 CST Arch=amd64 Os=linux KernelVersion=Linux-4.4.0-131-generic KernelHostname=lambda-Lenovo NumCpu=8 UpTime=36701 UsePermillage=35‰
cpu:
	Cpu_permillage=27‰  Avg1min=0.840000
memory:
	MemTotal=16779108352  MemUsePermillage=228‰  SwapTotal=2046816256  SwapUsePermillage=0‰
net:
	eth1: inKBps=0 outKBps=0
	eth0: inKBps=0 outKBps=0
	total TcpConnections=91 ESTABLISHED=42 TCP_LISTEN=34
disk:
	sda7 FsVfstype=TODO BytesAll=257588736000 BytesUsedPermillage=822‰ ReadBytes=0KBps  WriteBytes=124KBps ReadRequests=0qps WriteRequests=2qps
	sda2 FsVfstype=ext4 BytesAll=105192407040 BytesUsedPermillage=825‰ ReadBytes=0KBps  WriteBytes=0KBps ReadRequests=0qps WriteRequests=0qps
	sda5 FsVfstype=ext4 BytesAll=126692069376 BytesUsedPermillage=932‰ ReadBytes=0KBps  WriteBytes=0KBps ReadRequests=0qps WriteRequests=0qps
thermal:
	 acpitz0 = 27800
	 acpitz1 = 29800
	 x86_pkg_temp2 = 34000

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUstateinfo

type CPUstateinfo struct {
	CPUIdle       uint64 // time spent in the idle task
	CPUTotal      uint64 // total of all time fields
	CPUPermillage int    //usage, 50 meas 5%
	// contains filtered or unexported fields
}

CPUstateinfo CPU信息

type CPUstateinfos

type CPUstateinfos struct {
	CPUs   map[string]*CPUstateinfo
	CPUNum int

	Avg1min  float32
	Avg5min  float32
	Avg15min float32
}

CPUstateinfos 多核CPU信息

type DiskStates

type DiskStates struct {
	Device    string
	FsSpec    string
	FsFile    string
	FsVfstype string

	BytesAll             uint64
	BytesUsed            uint64
	BytesUsedPermillage  int
	InodesAll            uint64
	InodesUsed           uint64
	InodesUsedPermillage int

	ReadRequests  uint64 // Total number of reads completed successfully.
	ReadBytes     uint64 // Total number of Bytes read successfully.
	WriteRequests uint64 // total number of writes completed successfully.
	WriteBytes    uint64 // total number of Bytes written successfully.
	// contains filtered or unexported fields
}

DiskStates 磁盘状态

type Fsinfo

type Fsinfo struct {
	Disks map[string]*DiskStates
}

Fsinfo 文件系统信息

type Meminfo

type Meminfo struct {
	MemTotal         uint64
	MemAvailable     uint64
	MemUsePermillage int //usage, 50 meas 5%

	SwapTotal         uint64
	SwapFree          uint64
	SwapUsePermillage int //usage, 50 meas 5%
}

Meminfo 内存信息

type NetIf

type NetIf struct {
	Iface string
	IPs   map[int]string

	InBytes         uint64
	InPackages      uint64
	TotalInBytes    uint64
	TotalInPackages uint64

	OutBytes         uint64
	OutPackages      uint64
	TotalOutBytes    uint64
	TotalOutPackages uint64
	// contains filtered or unexported fields
}

NetIf 网卡信息

type NetWorkInfo

type NetWorkInfo struct {
	Cards map[string]*NetIf
	TCP   *TCPInfo
	TCP6  *TCPInfo
}

NetWorkInfo 网卡信息

type OSinfo

type OSinfo struct {
	UpTime        int64
	StartTime     int64
	UsePermillage int //usage, 50 meas 5%

	Arch           string
	Os             string
	KernelVersion  string
	KernelHostname string
	NumCPU         int
}

OSinfo 操作系统信息

type SysInfo

type SysInfo struct {
	OSEn bool
	OS   OSinfo

	CPUEn bool
	CPU   CPUstateinfos

	MemEn bool
	Mem   Meminfo

	NetEn bool
	Net   NetWorkInfo

	FsEn bool
	Fs   Fsinfo

	ThermalEn bool
	Thermal   Thermalinfo

	PeriodSec int // 任务执行周期,单位是秒
	// contains filtered or unexported fields
}

SysInfo 系统监视器的

func New

func New(periodSec int, callback func(*SysInfo)) *SysInfo

New 新新系统监视器

func (*SysInfo) Getsysteminfo

func (si *SysInfo) Getsysteminfo()

Getsysteminfo 获得系统资源信息

func (*SysInfo) Start

func (si *SysInfo) Start()

Start 开始系统监视器的定时任务

func (*SysInfo) Stop

func (si *SysInfo) Stop()

Stop 停止系统监视器的定时任务

type TCPInfo

type TCPInfo struct {
	TCPErrorStatus uint64
	TCPEstablished uint64
	TCPSynSent     uint64
	TCPSynRecv     uint64
	TCPFinWait1    uint64
	TCPFinWait2    uint64
	TCPTimewait    uint64
	TCPClose       uint64
	TCPCloseWait   uint64
	TCPLastAck     uint64
	TCPListen      uint64
	TCPClosing     uint64
	TCPConnections uint64 //total
}

TCPInfo tcp信息

type ThermalStates

type ThermalStates struct {
	Type string
	Temp int64
}

ThermalStates 温度状态

type Thermalinfo

type Thermalinfo struct {
	Thermal map[string]*ThermalStates
}

Thermalinfo 温度信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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