runtimeKit

package
v1.13.10 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package runtimeKit *

  • 主要是对如下包的封装:"runtime"

Index

Constants

This section is empty.

Variables

View Source
var GoRoot string

GoRoot GOROOT环境变量

View Source
var GoVersion string

GoVersion Golang的版本号

View Source
var PID = os.Getpid()

PID 当前进程的id

Functions

func GetAvailableMemoryPercent

func GetAvailableMemoryPercent() (float64, error)

GetAvailableMemoryPercent

@return e.g. (49.09634590148926, nil)

func GetAvailableMemoryRatio

func GetAvailableMemoryRatio() (float64, error)

GetAvailableMemoryRatio 获取可用内存的比例

@return e.g. (0.4909677505493164, nil)

“比例”和“比率”的区别? 全班人数50人,男生30,女生20,那男生的比例就是30/50,同理女生的就是20/50,那么男女的比率是什么呢,是30/20。

func GetCpuId

func GetCpuId() (string, error)

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 GetCpuPercent

func GetCpuPercent() (float64, error)

GetCpuPercent CPU使用率

func GetDockerIdList

func GetDockerIdList() ([]string, error)

GetDockerIdList

通过第三方库 gopsutil 实现.

func GetHostInfo

func GetHostInfo() (*host.InfoStat, error)

func GetMacAddresses

func GetMacAddresses() ([]string, error)

GetMacAddresses *

func GetUsedMemoryPercent

func GetUsedMemoryPercent() (float64, error)

GetUsedMemoryPercent

@return e.g. (50.903940200805664, nil)

func GetUsedMemoryRatio

func GetUsedMemoryRatio() (float64, error)

GetUsedMemoryRatio

@return e.g. (0.509037971496582, nil)

func PidExists

func PidExists(pid int32) (bool, error)

PidExists 判断 传参pid 对应的进程是否存在

PS: 通过 第三方库gopsutil 实现.

e.g. (-1) => (false, error(invalid pid -1)) (13120) => (true, nil) (13121) => (false, nil)

func SetSoftMemoryLimit

func SetSoftMemoryLimit(limit int64) (int64, error)

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

type DiskStat disk.UsageStat

DiskStat

Total = Used + Free

func GetDiskStat deprecated

func GetDiskStat() (*DiskStat, error)

GetDiskStat

Deprecated: 要考虑不同系统(主要是Linux和Mac),比较复杂,后续再完善吧.

参考: golang 获取cpu 内存 硬盘 使用率 信息 进程信息 https://blog.csdn.net/whatday/article/details/109620192

func (DiskStat) GetFreePercent

func (stat DiskStat) GetFreePercent() float64

GetFreePercent

e.g. 65.18472380640327

func (DiskStat) String

func (stat DiskStat) String() string

String

e.g. ""free: 300 GB, used: 160.43 GB, total: 460.43 GB, used percent: 34.84%""

type MemoryStat

type MemoryStat mem.VirtualMemoryStat

MemoryStat Total = Available + Used

func GetMemoryStat

func GetMemoryStat() (*MemoryStat, error)

GetMemoryStat 获取当前瞬间的内存状态

func (MemoryStat) GetAvailablePercent

func (stat MemoryStat) GetAvailablePercent() float64

GetAvailablePercent

e.g. 51.035356521606445

func (MemoryStat) String

func (stat MemoryStat) String() string

Jump to

Keyboard shortcuts

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