hoststat

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

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 7 Imported by: 12

README

host-stat

License GoDoc Build Status Go Report Card Code Cover

host-stat-go is a Go module for collecting host stat.

Overview

This module provided functions to collect cpu/mem/disk/io/load/uptime/kernel info of the host.

Work for popular LINUX distributions ONLY

Installation

go get -u github.com/likexian/host-stat-go

Importing

import (
    "github.com/likexian/host-stat-go"
)

Documentation

Visit the docs on GoDoc

Example

Get the memory stat

memStat, err := hoststat.GetMemStat()
if err == nil {
    // print total memory of host in KB
    fmt.Println(memStat.MemTotal)

    // print used memory of host in KB
    fmt.Println(memStat.MemUsed)

    // print free memory of host in KB
    fmt.Println(memStat.MemFree)

    // print used memory rate of host in percent
    fmt.Println(memStat.MemRate)
}

LICENSE

Copyright 2014-2019 Li Kexian

Licensed under the Apache License 2.0

About

DONATE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StateMap = map[string]string{
	"R": "running",
	"S": "sleeping",
	"D": "disk sleep",
	"T": "stopped",
	"Z": "zombie",
	"X": "dead",
}

StateMap is state map

Functions

func Author

func Author() string

Author returns package author

func GetRelease

func GetRelease() (name string, err error)

GetRelease returns host release info

func License

func License() string

License returns package license

func Version

func Version() string

Version returns package version

Types

type CPUInfo

type CPUInfo struct {
	ModelName string `json:"model_name"`
	CoreCount uint64 `json:"core_count"`
}

CPUInfo storing cpu info

func GetCPUInfo

func GetCPUInfo() (info CPUInfo, err error)

GetCPUInfo returns cpu info

type CPUStat

type CPUStat struct {
	User       uint64  `json:"user"`
	Nice       uint64  `json:"nice"`
	System     uint64  `json:"system"`
	Idle       uint64  `json:"idle"`
	IOWait     uint64  `json:"io_wait"`
	IRQ        uint64  `json:"irq"`
	SoftIRQS   uint64  `json:"soft_irqs"`
	Steal      uint64  `json:"steal"`
	Guest      uint64  `json:"guest"`
	GuestNice  uint64  `json:"guest_nice"`
	UserRate   float64 `json:"user_rate"`
	SystemRate float64 `json:"system_rate"`
	IdleRate   float64 `json:"idle_rate"`
	IOWaitRate float64 `json:"io_wait_rate"`
}

CPUStat storing cpu stat

func GetCPUStat

func GetCPUStat() (stat CPUStat, err error)

GetCPUStat returns cpu stat

type DiskStat

type DiskStat struct {
	Label    string  `json:"label"`
	Mount    string  `json:"mount"`
	Total    uint64  `json:"total"`
	Used     uint64  `json:"used"`
	Free     uint64  `json:"free"`
	UsedRate float64 `json:"used_rate"`
}

DiskStat storing disk stat

func GetDiskStat

func GetDiskStat() (stat []DiskStat, err error)

GetDiskStat returns all disk stat

type HostInfo

type HostInfo struct {
	HostName  string `json:"host_name"`
	OSType    string `json:"os_type"`
	OSRelease string `json:"os_release"`
	Version   string `json:"version"`
	Release   string `json:"release"`
	OSBit     string `json:"os_bit"`
}

HostInfo storing host info

func GetHostInfo

func GetHostInfo() (info HostInfo, err error)

GetHostInfo returns host info

type IOStat

type IOStat struct {
	Major        uint64 `json:"major"`         // major device number
	Minor        uint64 `json:"minor"`         // minor device number
	Name         string `json:"name"`          // device name
	ReadIOs      uint64 `json:"read_ios"`      // r/s total number of reads
	ReadMerges   uint64 `json:"read_merges"`   // rrqm/s number of read I/Os merged with in-queue I/O
	ReadSectors  uint64 `json:"read_sectors"`  // rsec/s number of 512 byte sectors read
	ReadTicks    uint64 `json:"read_ticks"`    // number of milliseconds spent reading
	WriteIOs     uint64 `json:"write_ios"`     // w/s total number of writes
	WriteMerges  uint64 `json:"write_merges"`  // wrqm/s number of write I/Os merged with in-queue I/O
	WriteSectors uint64 `json:"write_sectors"` // wsec/s number of 512 byte sectors written
	WriteTicks   uint64 `json:"write_ticks"`   // number of milliseconds spent writing
	InFlight     uint64 `json:"in_flight"`     // number of I/Os currently in progress
	IOTicks      uint64 `json:"io_ticks"`      // number of milliseconds spent doing I/Os(in flight)
	TimeInQueue  uint64 `json:"time_in_queue"` // total wait time for all requests in milliseconds
	ReadBytes    uint64 `json:"read_bytes"`    // rB/s
	WriteBytes   uint64 `json:"write_bytes"`   // wB/s
}

IOStat storing io stat

func GetIOStat

func GetIOStat() (stat []IOStat, err error)

GetIOStat returns io stat

type LoadStat

type LoadStat struct {
	LoadNow      float64 `json:"load_now"`
	LoadPre      float64 `json:"load_pre"`
	LoadFar      float64 `json:"load_far"`
	ProcessTotal uint64  `json:"process_total"`
	ProcessRun   uint64  `json:"process_run"`
	ProcessIdle  uint64  `json:"process_idle"`
}

LoadStat storing load stat

func GetLoadStat

func GetLoadStat() (stat LoadStat, err error)

GetLoadStat returns load stat

type MemStat

type MemStat struct {
	MemTotal  uint64  `json:"mem_total"`
	MemUsed   uint64  `json:"mem_used"`
	MemFree   uint64  `json:"mem_free"`
	Buffers   uint64  `json:"buffers"`
	Cached    uint64  `json:"cached"`
	SwapTotal uint64  `json:"swap_total"`
	SwapUsed  uint64  `json:"swap_used"`
	SwapFree  uint64  `json:"swap_free"`
	MemRate   float64 `json:"mem_rate"`
	SwapRate  float64 `json:"swap_rate"`
}

MemStat storing memory stat

func GetMemStat

func GetMemStat() (stat MemStat, err error)

GetMemStat returns memory stat

type NetStat

type NetStat struct {
	Device       string `json:"device"`
	RXBytes      uint64 `json:"rx_bytes"`
	RXPackets    uint64 `json:"rx_packets"`
	RXErrs       uint64 `json:"rx_errs"`
	RXDrop       uint64 `json:"rx_drop"`
	RXFifo       uint64 `json:"rx_fifo"`
	RXFrame      uint64 `json:"rx_frame"`
	RXCompressed uint64 `json:"rx_compressed"`
	RXMulticast  uint64 `json:"rx_multicase"`
	TXBytes      uint64 `json:"tx_bytes"`
	TXPackets    uint64 `json:"tx_packetss"`
	TXErrs       uint64 `json:"tx_errs"`
	TXDrop       uint64 `json:"tx_drop"`
	TXFifo       uint64 `json:"tx_fifo"`
	TXColls      uint64 `json:"tx_colls"`
	TXCarrier    uint64 `json:"tx_carrier"`
	TXCompressed uint64 `json:"tx_compressed"`
}

NetStat storing net stat

func GetNetStat

func GetNetStat() (stat []NetStat, err error)

GetNetStat returns net stat

type ProcessStat

type ProcessStat struct {
	Pid   int    `json:"pid"`
	Name  string `json:"name"`
	State string `json:"state"`
}

ProcessStat storing process stat

func GetProcessStat

func GetProcessStat() (stat []ProcessStat, err error)

GetProcessStat returns process stat

type UptimeStat

type UptimeStat struct {
	Uptime   float64 `json:"uptime"`
	IdleTime float64 `json:"idle_time"`
	IdleRate float64 `json:"idle_rate"`
}

UptimeStat storing uptime stat

func GetUptimeStat

func GetUptimeStat() (stat UptimeStat, err error)

GetUptimeStat returns uptime stat

Jump to

Keyboard shortcuts

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