goinfo

package module
v0.0.0-...-56fe96c Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2014 License: MIT Imports: 6 Imported by: 0

README

goinfo

======

Getting Server system info by reading file in '/proc', such as CPU, Memory, Disk stat, IO, etc.

Installation

go get github.com/luosangnanka/goinfo

Features

  • Fast, and little resource consumption.

    Only because it works by reading linux file but not depand on any linux command such as 'free', etc.

  • Good compatibility. It works in any Linux machines.

Reading File List.

CPU: 		"/proc/stat"       	
Memory: 	"/proc/meminfo"    	
Net: 		"/proc/net/dev"    	
Host: 		"/proc/uptime"	  	
Disk: 		"/proc/diskstats"  	
Loadavg: 	"/proc/loadavg"    	
TCP & UDP: 	"/proc/net/snmp"   	

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSize

type ByteSize float64

ByteSize type for the format of KB MB GB TB.

const (

	// KB size.
	KB ByteSize = 1 << (10 * iota)
	// MB size.
	MB
	// GB size.
	GB
	// TB size.
	TB
)

func (ByteSize) String

func (b ByteSize) String() (rs string)

String format the size into the KB MB GB TB format.

type CPUInfo

type CPUInfo struct {
	Total   int64 `json:"total"`
	User    int64 `json:"user"`
	Nice    int64 `json:"nice"`
	System  int64 `json:"system"`
	Idle    int64 `json:"idle"`
	Iowait  int64 `json:"iowait"`
	Irq     int64 `json:"irq"`
	Softirq int64 `json:"softirq"`
}

CPUInfo cpu info struct.

func CPU

func CPU() (info []*CPUInfo, err error)

CPU return the default info finder's CPU info.

func (*CPUInfo) String

func (c *CPUInfo) String() (cpu string)

String format the cpu struct.

type DiskStat

type DiskStat struct {
	ID     int64  `json:"id"`     // 编号
	SdName string `json:"sdname"` // 设备名称

	RCompleNum      int64 `json:"r_comple_num"`       // 读完成次数
	RCompleMergeNum int64 `json:"r_comple_merge_num"` // 合并完成就
	RSectorsNum     int64 `json:"r_sectors_num"`      // 读扇区次数
	RSpentMill      int64 `json:"r_spent_mill"`       // 读操作花费毫秒数

	WConpleNum      int64 `json:"w_conple_num"`       // 写完成次数
	WCompleMergeNum int64 `json:"w_comple_merge_num"` // 合并写完成次数
	WSectirsNum     int64 `json:"w_sectirs_num"`      // 写扇区次数
	WSpentMill      int64 `json:"w_spent_mill"`       // 写操作花费毫秒数

	RWResquestNum int64 `json:"rw_resquest_num"` // 正在处理的输入/输出请求书
	RWSpentMill   int64 `json:"rw_spent_mill"`   // 输入/输出操作花费的毫秒数
	RWSpentMillW  int64 `json:"rw_spent_mill_w"` // 输入/输出操作花费的加权毫秒数
}

DiskStat disk stat info struct.

func Disk

func Disk() (disk []*DiskStat, err error)

Disk return the default info finder's Disk info.

func (*DiskStat) String

func (d *DiskStat) String() (disk string)

String format the disk stat struct.

type Free

type Free struct {
	Mem  *Mem  `json:"mem"`
	Swap *Swap `json:"swap"`
}

Free is mem info sum.

func Memory

func Memory() (free *Free, err error)

Memory return the default info finder's Memory info.

func (*Free) String

func (f *Free) String() (free string)

String format the free struct.

type HostName

type HostName struct {
	Name   string `json:"name"`
	Boot   string `json:"boot"`
	Uptime string `json:"uptime"`
}

HostName host name and boot time struct.

func Host

func Host() (host *HostName, err error)

Host return the default info finder's Host info.

func (*HostName) String

func (h *HostName) String() (host string)

String format the host struct.

type Loadavg

type Loadavg struct {
	La1       float64 `json:"la1"`
	La5       float64 `json:"la2"`
	La15      float64 `json:"la3"`
	Processes string  `json:"processes"`
	MaxPid    int64   `json:"max_pid"`
}

Loadavg is load info struct.

func Load

func Load() (load *Loadavg, err error)

Load return the default info finder's Load info.

func (*Loadavg) String

func (l *Loadavg) String() (load string)

String format the loadavg struct.

type Mem

type Mem struct {
	Total   ByteSize `json:"total"`
	Used    ByteSize `json:"used"`
	Free    ByteSize `json:"free"`
	Buffers ByteSize `json:"buffers"`
	Cached  ByteSize `json:"cached"`
}

Mem is mem info struct.

func (*Mem) String

func (m *Mem) String() (mem string)

String format the Mem struct.

type Swap

type Swap struct {
	Total ByteSize `json:"total"`
	Used  ByteSize `json:"used"`
	Free  ByteSize `json:"free"`
}

Swap is swap info struct.

func (*Swap) String

func (s *Swap) String() (swap string)

String format the Swap struct.

type Tcp

type Tcp struct {
	ActiveOpens  int64
	PassiveOpens int64
	InSegs       int64
	OutSegs      int64
	RetransSegs  int64
}

Tcp is tcp info struct.

func TCP

func TCP() (tcp *Tcp, err error)

TCP return the default info finder's tcp info.

func (*Tcp) String

func (t *Tcp) String() (tcp string)

String format the tcp struct.

type Traffic

type Traffic struct {
	Name     string `json:"name"`
	Receive  int64  `json:"receive"`
	Transmit int64  `json:"transmit"`
	Time     string `json:"time"`
}

Traffic is net transmit info struct.

func Net

func Net() (traffic []*Traffic, err error)

Net return the default info finder's Net info.

func (*Traffic) String

func (t *Traffic) String() (net string)

String format the traffic struct.

type Udp

type Udp struct {
	InDatagrams  int64
	NoPorts      int64
	InErrors     int64
	OutDatagrams int64
}

Udp is udp info struct.

func UDP

func UDP() (udp *Udp, err error)

UDP return the default info finder's udp info.

func (*Udp) String

func (u *Udp) String() (udp string)

String format the udp struct.

type Xminfo

type Xminfo struct {
}

Xminfo info finder.

func NewXminfo

func NewXminfo() (xminfo *Xminfo)

NewXminfo new a info finder.

func (*Xminfo) CPU

func (x *Xminfo) CPU() (info []*CPUInfo, err error)

CPU getting cpu info by reading linux /proc/stat file.

func (*Xminfo) Disk

func (x *Xminfo) Disk() (disk []*DiskStat, err error)

Disk getting disk stat info by reading linux /proc/diskstats file.

func (*Xminfo) Host

func (x *Xminfo) Host() (host *HostName, err error)

Host getting host info by reading linux /proc/uptime file.

func (*Xminfo) Load

func (x *Xminfo) Load() (load *Loadavg, err error)

Load getting load info by reading linux /proc/loadavg file.

func (*Xminfo) Memory

func (x *Xminfo) Memory() (free *Free, err error)

Memory getting host memory by reading linux /proc/meminfo file.

func (*Xminfo) Net

func (x *Xminfo) Net() (traffic []*Traffic, err error)

Net getting net info by reading linux /proc/net/dev file.

func (*Xminfo) TCP

func (x *Xminfo) TCP() (tcp *Tcp, err error)

TCP getting tcp info by reading linux /proc/net/snmp file.

func (*Xminfo) UDP

func (x *Xminfo) UDP() (udp *Udp, err error)

UDP getting udp info by reading linux /proc/net/snmp file.

Jump to

Keyboard shortcuts

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