Documentation ¶
Overview ¶
Package runtimeKit *
- 主要是对如下包的封装:"runtime"
Index ¶
- Variables
- func GetAvailableMemoryPercent() (float64, error)
- func GetAvailableMemoryRatio() (float64, error)
- func GetCpuId() (string, error)
- func GetCpuNumber() int
- func GetCpuPercent() (float64, error)
- func GetDockerIdList() ([]string, error)
- func GetHostInfo() (*host.InfoStat, error)
- func GetMacAddresses() ([]string, error)
- func GetUsedMemoryPercent() (float64, error)
- func GetUsedMemoryRatio() (float64, error)
- func PidExists(pid int32) (bool, error)
- func SetSoftMemoryLimit(limit int64) (int64, error)
- type DiskStat
- func GetDiskStat() (*DiskStat, error)deprecated
- type MemoryStat
Constants ¶
This section is empty.
Variables ¶
var GoRoot string
GoRoot GOROOT环境变量
var GoVersion string
GoVersion Golang的版本号
var PID = os.Getpid()
PID 当前进程的id
Functions ¶
func GetAvailableMemoryRatio ¶
GetAvailableMemoryRatio 获取可用内存的比例
@return e.g. (0.4909677505493164, nil)
“比例”和“比率”的区别? 全班人数50人,男生30,女生20,那男生的比例就是30/50,同理女生的就是20/50,那么男女的比率是什么呢,是30/20。
func GetCpuId ¶
GetCpuId
PS: cpu.Info() 目前仅支持Windows环境,不支持:Mac环境(M1)、Linux环境.
Linux下用命令查看CPU ID: https://blog.csdn.net/benwdm/article/details/84685292
func GetCpuNumber ¶
func GetCpuNumber() int
func GetHostInfo ¶
func GetMacAddresses ¶
GetMacAddresses *
- 参考:https://blog.csdn.net/chixielao6059/article/details/100860506 *
- MAC地址:主机网卡的物理地址.
func PidExists ¶
PidExists 判断 传参pid 对应的进程是否存在
PS: 通过 第三方库gopsutil 实现.
e.g. (-1) => (false, error(invalid pid -1)) (13120) => (true, nil) (13121) => (false, nil)
func SetSoftMemoryLimit ¶
SetSoftMemoryLimit 软内存限制(soft memory limit)
PS: (1) This limit will be respected even if GOGC=off (or, if SetGCPercent(-1) is executed). (2) 默认memory limit是math.MaxInt64(即第一次调用debug.SetMemoryLimit()的返回值为math.MaxInt64).
@param limit 单位: B(byte;字节) @return 之前的内存限制
Types ¶
type DiskStat ¶
DiskStat
Total = Used + Free
func GetDiskStat
deprecated
GetDiskStat
Deprecated: 要考虑不同系统(主要是Linux和Mac),比较复杂,后续再完善吧.
参考: golang 获取cpu 内存 硬盘 使用率 信息 进程信息 https://blog.csdn.net/whatday/article/details/109620192
type MemoryStat ¶
type MemoryStat mem.VirtualMemoryStat
MemoryStat Total = Available + Used
func (MemoryStat) GetAvailablePercent ¶
func (stat MemoryStat) GetAvailablePercent() float64
GetAvailablePercent
e.g. 51.035356521606445
func (MemoryStat) String ¶
func (stat MemoryStat) String() string