proc

package
v0.0.0-...-06ce4da Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUInfo

type CPUInfo struct {
	Processors []Processor `json:"processors"`
}

func ReadCPUInfo

func ReadCPUInfo() (*CPUInfo, error)

func (*CPUInfo) IsOK

func (self *CPUInfo) IsOK() bool

func (*CPUInfo) NumCPU

func (self *CPUInfo) NumCPU() int

func (*CPUInfo) NumCore

func (self *CPUInfo) NumCore() int

func (*CPUInfo) NumPhysicalCPU

func (self *CPUInfo) NumPhysicalCPU() int

type CPUStat

type CPUStat struct {
	Id        string `json:"id"`
	User      uint64 `json:"user"`
	Nice      uint64 `json:"nice"`
	System    uint64 `json:"system"`
	Idle      uint64 `json:"idle"`
	IOWait    uint64 `json:"iowait"`
	IRQ       uint64 `json:"irq"`
	SoftIRQ   uint64 `json:"softirq"`
	Steal     uint64 `json:"steal"`
	Guest     uint64 `json:"guest"`
	GuestNice uint64 `json:"guest_nice"`
}

cpu

func (*CPUStat) GetCpuIdle

func (cs *CPUStat) GetCpuIdle() uint64

func (*CPUStat) GetCpuTotal

func (cs *CPUStat) GetCpuTotal() uint64

func (*CPUStat) GetCpuTotalTicks

func (cs *CPUStat) GetCpuTotalTicks() uint64

type Disk

type Disk struct {
	All        uint64 `json:"all"`  //byte,总磁盘空间
	Used       uint64 `json:"used"` //byte,已用
	Free       uint64 `json:"free"` //byte,空闲
	FreeInodes uint64 `json:"freeInodes"`
}

单位byte

func ReadDisk

func ReadDisk(path string) (*Disk, error)

获取指定目录下的磁盘空间信息

func (*Disk) GetFreeByte

func (d *Disk) GetFreeByte() uint64

func (*Disk) GetTotalCapacityByte

func (d *Disk) GetTotalCapacityByte() uint64

func (*Disk) GetUsedByte

func (d *Disk) GetUsedByte() uint64

type DiskStat

type DiskStat struct {
	SampledTime
	Major        int    `json:"major"`         // major device number
	Minor        int    `json:"minor"`         // minor device number
	Name         string `json:"name"`          // device name
	ReadIOs      uint64 `json:"read_ios"`      // number of read I/Os processed
	ReadMerges   uint64 `json:"read_merges"`   // number of read I/Os merged with in-queue I/O
	ReadSectors  uint64 `json:"read_sectors"`  // number of 512 byte sectors read
	ReadTicks    uint64 `json:"read_ticks"`    // total wait time for read requests in milliseconds
	WriteIOs     uint64 `json:"write_ios"`     // number of write I/Os processed
	WriteMerges  uint64 `json:"write_merges"`  // number of write I/Os merged with in-queue I/O
	WriteSectors uint64 `json:"write_sectors"` // number of 512 byte sectors written
	WriteTicks   uint64 `json:"write_ticks"`   // total wait time for write requests in milliseconds
	InFlight     uint64 `json:"in_flight"`     // number of I/Os currently in flight
	IOTicks      uint64 `json:"io_ticks"`      // total time this block device has been active in milliseconds
	TimeInQueue  uint64 `json:"time_in_queue"` // total wait time for all requests in milliseconds
}

DiskStat is disk statistics to help measure disk activity.

Note:

  • On a very busy or long-lived system values may wrap.
  • No kernel locks are held while modifying these counters. This implies that minor inaccuracies may occur.

More more info see: https://www.kernel.org/doc/Documentation/iostats.txt and https://www.kernel.org/doc/Documentation/block/stat.txt

func ReadDiskStats

func ReadDiskStats() ([]DiskStat, error)

func (*DiskStat) GetIOTicks

func (ds *DiskStat) GetIOTicks() time.Duration

GetIOTicks returns the duration the disk has been active.

func (*DiskStat) GetName

func (ds *DiskStat) GetName() string

disk name

func (*DiskStat) GetReadBytes

func (ds *DiskStat) GetReadBytes() int64

GetReadBytes returns the number of bytes read.

func (*DiskStat) GetReadTicks

func (ds *DiskStat) GetReadTicks() time.Duration

GetReadTicks returns the duration waited for read requests.

func (*DiskStat) GetTimeInQueue

func (ds *DiskStat) GetTimeInQueue() time.Duration

GetTimeInQueue returns the duration waited for all requests.

func (*DiskStat) GetWriteBytes

func (ds *DiskStat) GetWriteBytes() int64

GetWriteBytes returns the number of bytes written.

func (*DiskStat) GetWriteTicks

func (ds *DiskStat) GetWriteTicks() time.Duration

GetWriteTicks returns the duration waited for write requests.

type LoadAvg

type LoadAvg struct {
	Last1Min       float64 `json:"last1min"`
	Last5Min       float64 `json:"last5min"`
	Last15Min      float64 `json:"last15min"`
	ProcessRunning uint64  `json:"process_running"`
	ProcessTotal   uint64  `json:"process_total"`
	LastPID        uint64  `json:"last_pid"`
}

func ReadLoadAvg

func ReadLoadAvg() (*LoadAvg, error)

func (*LoadAvg) GetLast15Min

func (la *LoadAvg) GetLast15Min() float64

func (*LoadAvg) GetLast1Min

func (la *LoadAvg) GetLast1Min() float64

func (*LoadAvg) GetLast5Min

func (la *LoadAvg) GetLast5Min() float64

type MemInfo

type MemInfo struct {
	MemTotal          uint64 `json:"mem_total"`
	MemFree           uint64 `json:"mem_free"`
	MemAvailable      uint64 `json:"mem_available"`
	Buffers           uint64 `json:"buffers"`
	Cached            uint64 `json:"cached"`
	SwapCached        uint64 `json:"swap_cached"`
	Active            uint64 `json:"active"`
	Inactive          uint64 `json:"inactive"`
	ActiveAnon        uint64 `json:"active_anon" field:"Active(anon)"`
	InactiveAnon      uint64 `json:"inactive_anon" field:"Inactive(anon)"`
	ActiveFile        uint64 `json:"active_file" field:"Active(file)"`
	InactiveFile      uint64 `json:"inactive_file" field:"Inactive(file)"`
	Unevictable       uint64 `json:"unevictable"`
	Mlocked           uint64 `json:"mlocked"`
	SwapTotal         uint64 `json:"swap_total"`
	SwapFree          uint64 `json:"swap_free"`
	Dirty             uint64 `json:"dirty"`
	Writeback         uint64 `json:"write_back"`
	AnonPages         uint64 `json:"anon_pages"`
	Mapped            uint64 `json:"mapped"`
	Shmem             uint64 `json:"shmem"`
	Slab              uint64 `json:"slab"`
	SReclaimable      uint64 `json:"s_reclaimable"`
	SUnreclaim        uint64 `json:"s_unclaim"`
	KernelStack       uint64 `json:"kernel_stack"`
	PageTables        uint64 `json:"page_tables"`
	NFS_Unstable      uint64 `json:"nfs_unstable"`
	Bounce            uint64 `json:"bounce"`
	WritebackTmp      uint64 `json:"writeback_tmp"`
	CommitLimit       uint64 `json:"commit_limit"`
	Committed_AS      uint64 `json:"committed_as"`
	VmallocTotal      uint64 `json:"vmalloc_total"`
	VmallocUsed       uint64 `json:"vmalloc_used"`
	VmallocChunk      uint64 `json:"vmalloc_chunk"`
	HardwareCorrupted uint64 `json:"hardware_corrupted"`
	AnonHugePages     uint64 `json:"anon_huge_pages"`
	HugePages_Total   uint64 `json:"huge_pages_total"`
	HugePages_Free    uint64 `json:"huge_pages_free"`
	HugePages_Rsvd    uint64 `json:"huge_pages_rsvd"`
	HugePages_Surp    uint64 `json:"huge_pages_surp"`
	Hugepagesize      uint64 `json:"hugepagesize"`
	DirectMap4k       uint64 `json:"direct_map_4k"`
	DirectMap2M       uint64 `json:"direct_map_2M"`
	DirectMap1G       uint64 `json:"direct_map_1G"`
}

单位kB

func ReadMemInfo

func ReadMemInfo() (*MemInfo, error)

func (*MemInfo) GetMemAvailableKB

func (mi *MemInfo) GetMemAvailableKB() uint64

func (*MemInfo) GetMemBuffersKB

func (mi *MemInfo) GetMemBuffersKB() uint64

func (*MemInfo) GetMemCachedKB

func (mi *MemInfo) GetMemCachedKB() uint64

func (*MemInfo) GetMemFreeKB

func (mi *MemInfo) GetMemFreeKB() uint64

func (*MemInfo) GetMemTotalKB

func (mi *MemInfo) GetMemTotalKB() uint64

func (*MemInfo) GetSwapFreeKB

func (mi *MemInfo) GetSwapFreeKB() uint64

func (*MemInfo) GetSwapTotalKB

func (mi *MemInfo) GetSwapTotalKB() uint64

type NetDevStat

type NetDevStat struct {
	SampledTime
	Iface        string `json:"iface"`
	RxBytes      uint64 `json:"rxbytes"`
	RxPackets    uint64 `json:"rxpackets"`
	RxErrs       uint64 `json:"rxerrs"`
	RxDrop       uint64 `json:"rxdrop"`
	RxFifo       uint64 `json:"rxfifo"`
	RxFrame      uint64 `json:"rxframe"`
	RxCompressed uint64 `json:"rxcompressed"`
	RxMulticast  uint64 `json:"rxmulticast"`
	TxBytes      uint64 `json:"txbytes"`
	TxPackets    uint64 `json:"txpackets"`
	TxErrs       uint64 `json:"txerrs"`
	TxDrop       uint64 `json:"txdrop"`
	TxFifo       uint64 `json:"txfifo"`
	TxColls      uint64 `json:"txcolls"`
	TxCarrier    uint64 `json:"txcarrier"`
	TxCompressed uint64 `json:"txcompressed"`
}

func ReadNetDevStat

func ReadNetDevStat() ([]NetDevStat, error)

func (*NetDevStat) GetIfaceName

func (nds *NetDevStat) GetIfaceName() string

func (*NetDevStat) GetRxBytes

func (nds *NetDevStat) GetRxBytes() uint64

func (*NetDevStat) GetTxBytes

func (nds *NetDevStat) GetTxBytes() uint64

type ProcSystemStat

type ProcSystemStat struct {
	SampledTime
	CPUStatAll      *CPUStat   `json:"cpu_all"`
	CPUCoreStats    []*CPUStat `json:"cpus"`
	Interrupts      uint64     `json:"intr"`
	ContextSwitches uint64     `json:"ctxt"`
	BootTime        time.Time  `json:"btime"`
	Processes       uint64     `json:"processes"`
	ProcsRunning    uint64     `json:"procs_running"`
	ProcsBlocked    uint64     `json:"procs_blocked"`
}

记录的proc/stat的信息

func ReadProcSystemStat

func ReadProcSystemStat() (*ProcSystemStat, error)

func (*ProcSystemStat) GetCpuStatAll

func (pss *ProcSystemStat) GetCpuStatAll() *CPUStat

type Processor

type Processor struct {
	Id         int64    `json:"id"`
	VendorId   string   `json:"vendor_id"`
	Model      int64    `json:"model"`
	ModelName  string   `json:"model_name"`
	Flags      []string `json:"flags"`
	Cores      int64    `json:"cores"`
	MHz        float64  `json:"mhz"`
	CacheSize  int64    `json:"cache_size"` // KB
	PhysicalId int64    `json:"physical_id"`
	CoreId     int64    `json:"core_id"`
}

type SampledTime

type SampledTime struct {
	SampleTime time.Time
}

func (*SampledTime) GetSampleTime

func (st *SampledTime) GetSampleTime() time.Time

func (*SampledTime) UpdateSampledTime

func (st *SampledTime) UpdateSampledTime(t *time.Time)

type Uptime

type Uptime struct {
	Total float64 `json:"total"` //seconds,Wall clock since boot
	Idle  float64 `json:"idle"`  //seconds,combined idle time of all cpus
}

func ReadUptime

func ReadUptime() (*Uptime, error)

func (*Uptime) CalculateIdlePercent

func (self *Uptime) CalculateIdlePercent(cores int16) float64

func (*Uptime) GetIdleDuration

func (self *Uptime) GetIdleDuration() time.Duration

func (*Uptime) GetTotalDuration

func (self *Uptime) GetTotalDuration() time.Duration

type VMStat

type VMStat struct {
	SampledTime
	NrFreePages                   uint64 `json:"nr_free_pages"`
	NrAllocBatch                  uint64 `json:"nr_alloc_batch"`
	NrInactiveAnon                uint64 `json:"nr_inactive_anon"`
	NrActiveAnon                  uint64 `json:"nr_active_anon"`
	NrInactiveFile                uint64 `json:"nr_inactive_file"`
	NrActiveFile                  uint64 `json:"nr_active_file"`
	NrUnevictable                 uint64 `json:"nr_unevictable"`
	NrMlock                       uint64 `json:"nr_mlock"`
	NrAnonPages                   uint64 `json:"nr_anon_pages"`
	NrMapped                      uint64 `json:"nr_mapped"`
	NrFilePages                   uint64 `json:"nr_file_pages"`
	NrDirty                       uint64 `json:"nr_dirty"`
	NrWriteback                   uint64 `json:"nr_writeback"`
	NrSlabReclaimable             uint64 `json:"nr_slab_reclaimable"`
	NrSlabUnreclaimable           uint64 `json:"nr_slab_unreclaimable"`
	NrPageTablePages              uint64 `json:"nr_page_table_pages"`
	NrKernelStack                 uint64 `json:"nr_kernel_stack"`
	NrUnstable                    uint64 `json:"nr_unstable"`
	NrBounce                      uint64 `json:"nr_bounce"`
	NrVmscanWrite                 uint64 `json:"nr_vmscan_write"`
	NrVmscanImmediateReclaim      uint64 `json:"nr_vmscan_immediate_reclaim"`
	NrWritebackTemp               uint64 `json:"nr_writeback_temp"`
	NrIsolatedAnon                uint64 `json:"nr_isolated_anon"`
	NrIsolatedFile                uint64 `json:"nr_isolated_file"`
	NrShmem                       uint64 `json:"nr_shmem"`
	NrDirtied                     uint64 `json:"nr_dirtied"`
	NrWritten                     uint64 `json:"nr_written"`
	NumaHit                       uint64 `json:"numa_hit"`
	NumaMiss                      uint64 `json:"numa_miss"`
	NumaForeign                   uint64 `json:"numa_foreign"`
	NumaInterleave                uint64 `json:"numa_interleave"`
	NumaLocal                     uint64 `json:"numa_local"`
	NumaOther                     uint64 `json:"numa_other"`
	WorkingsetRefault             uint64 `json:"workingset_refault"`
	WorkingsetActivate            uint64 `json:"workingset_activate"`
	WorkingsetNodereclaim         uint64 `json:"workingset_nodereclaim"`
	NrAnonTransparentHugepages    uint64 `json:"nr_anon_transparent_hugepages"`
	NrFreeCma                     uint64 `json:"nr_free_cma"`
	NrDirtyThreshold              uint64 `json:"nr_dirty_threshold"`
	NrDirtyBackgroundThreshold    uint64 `json:"nr_dirty_background_threshold"`
	PagePagein                    uint64 `json:"pgpgin"`
	PagePageout                   uint64 `json:"pgpgout"`
	PageSwapin                    uint64 `json:"pswpin"`
	PageSwapout                   uint64 `json:"pswpout"`
	PageAllocDMA                  uint64 `json:"pgalloc_dma"`
	PageAllocDMA32                uint64 `json:"pgalloc_dma32"`
	PageAllocNormal               uint64 `json:"pgalloc_normal"`
	PageAllocMovable              uint64 `json:"pgalloc_movable"`
	PageFree                      uint64 `json:"pgfree"`
	PageActivate                  uint64 `json:"pgactivate"`
	PageDeactivate                uint64 `json:"pgdeactivate"`
	PageFault                     uint64 `json:"pgfault"`
	PageMajorFault                uint64 `json:"pgmajfault"`
	PageRefillDMA                 uint64 `json:"pgrefill_dma"`
	PageRefillDMA32               uint64 `json:"pgrefill_dma32"`
	PageRefillMormal              uint64 `json:"pgrefill_normal"`
	PageRefillMovable             uint64 `json:"pgrefill_movable"`
	PageStealKswapdDMA            uint64 `json:"pgsteal_kswapd_dma"`
	PageStealKswapdDMA32          uint64 `json:"pgsteal_kswapd_dma32"`
	PageStealKswapdNormal         uint64 `json:"pgsteal_kswapd_normal"`
	PageStealKswapdMovable        uint64 `json:"pgsteal_kswapd_movable"`
	PageStealDirectDMA            uint64 `json:"pgsteal_direct_dma"`
	PageStealDirectDMA32          uint64 `json:"pgsteal_direct_dma32"`
	PageStealDirectNormal         uint64 `json:"pgsteal_direct_normal"`
	PageStealDirectMovable        uint64 `json:"pgsteal_direct_movable"`
	PageScanKswapdDMA             uint64 `json:"pgscan_kswapd_dma"`
	PageScanKswapdDMA32           uint64 `json:"pgscan_kswapd_dma32"`
	PageScanKswapdNormal          uint64 `json:"pgscan_kswapd_normal"`
	PageScanKswapdMovable         uint64 `json:"pgscan_kswapd_movable"`
	PageScanDirectDMA             uint64 `json:"pgscan_direct_dma"`
	PageScanDirectDMA32           uint64 `json:"pgscan_direct_dma32"`
	PageScanDirectNormal          uint64 `json:"pgscan_direct_normal"`
	PageScanDirectMovable         uint64 `json:"pgscan_direct_movable"`
	PageScanDirectThrottle        uint64 `json:"pgscan_direct_throttle"`
	ZoneReclaimFailed             uint64 `json:"zone_reclaim_failed"`
	PageInodeSteal                uint64 `json:"pginodesteal"`
	SlabsScanned                  uint64 `json:"slabs_scanned"`
	KswapdInodesteal              uint64 `json:"kswapd_inodesteal"`
	KswapdLowWatermarkHitQuickly  uint64 `json:"kswapd_low_wmark_hit_quickly"`
	KswapdHighWatermarkHitQuickly uint64 `json:"kswapd_high_wmark_hit_quickly"`
	PageoutRun                    uint64 `json:"pageoutrun"`
	AllocStall                    uint64 `json:"allocstall"`
	PageRotated                   uint64 `json:"pgrotated"`
	DropPagecache                 uint64 `json:"drop_pagecache"`
	DropSlab                      uint64 `json:"drop_slab"`
	NumaPteUpdates                uint64 `json:"numa_pte_updates"`
	NumaHugePteUpdates            uint64 `json:"numa_huge_pte_updates"`
	NumaHintFaults                uint64 `json:"numa_hint_faults"`
	NumaHintFaults_local          uint64 `json:"numa_hint_faults_local"`
	NumaPagesMigrated             uint64 `json:"numa_pages_migrated"`
	PageMigrateSuccess            uint64 `json:"pgmigrate_success"`
	PageMigrateFail               uint64 `json:"pgmigrate_fail"`
	CompactMigrateScanned         uint64 `json:"compact_migrate_scanned"`
	CompactFreeScanned            uint64 `json:"compact_free_scanned"`
	CompactIsolated               uint64 `json:"compact_isolated"`
	CompactStall                  uint64 `json:"compact_stall"`
	CompactFail                   uint64 `json:"compact_fail"`
	CompactSuccess                uint64 `json:"compact_success"`
	HtlbBuddyAllocSuccess         uint64 `json:"htlb_buddy_alloc_success"`
	HtlbBuddyAllocFail            uint64 `json:"htlb_buddy_alloc_fail"`
	UnevictablePagesCulled        uint64 `json:"unevictable_pgs_culled"`
	UnevictablePagesScanned       uint64 `json:"unevictable_pgs_scanned"`
	UnevictablePagesRescued       uint64 `json:"unevictable_pgs_rescued"`
	UnevictablePagesMlocked       uint64 `json:"unevictable_pgs_mlocked"`
	UnevictablePagesMunlocked     uint64 `json:"unevictable_pgs_munlocked"`
	UnevictablePagesCleared       uint64 `json:"unevictable_pgs_cleared"`
	UnevictablePagesStranded      uint64 `json:"unevictable_pgs_stranded"`
	THPFaultAlloc                 uint64 `json:"thp_fault_alloc"`
	THPFaultFallback              uint64 `json:"thp_fault_fallback"`
	THPCollapseAlloc              uint64 `json:"thp_collapse_alloc"`
	THPCollapseAllocFailed        uint64 `json:"thp_collapse_alloc_failed"`
	THPSplit                      uint64 `json:"thp_split"`
	THPZeroPageAlloc              uint64 `json:"thp_zero_page_alloc"`
	THPZeroPageAllocFailed        uint64 `json:"thp_zero_page_alloc_failed"`
}

func ReadVMStat

func ReadVMStat() (*VMStat, error)

func (*VMStat) GetPagePagein

func (vm *VMStat) GetPagePagein() uint64

func (*VMStat) GetPagePageout

func (vm *VMStat) GetPagePageout() uint64

func (*VMStat) GetPageSwapin

func (vm *VMStat) GetPageSwapin() uint64

func (*VMStat) GetPageSwapout

func (vm *VMStat) GetPageSwapout() uint64

Jump to

Keyboard shortcuts

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