Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CPUInfo ¶
type CPUInfo struct {
LogicalCores int
UsagePercent float64 // 总体使用率,0~100
LoadAvg [3]float64 // 1/5/15 分钟平均负载(Linux)
}
CPUInfo 包含 CPU 核心数和负载信息
func GetCPUInfo ¶
GetCPUInfo 获取当前 CPU 信息
Example ¶
ExampleGetCPUInfo 展示如何使用GetCPUInfo函数
cpuInfo, err := GetCPUInfo()
if err != nil {
fmt.Printf("获取CPU信息失败: %v\n", err)
return
}
fmt.Printf("CPU 核心数: %d\n", cpuInfo.LogicalCores)
fmt.Printf("CPU 使用率: %.2f%%\n", cpuInfo.UsagePercent)
fmt.Printf("负载平均: %.2f, %.2f, %.2f\n", cpuInfo.LoadAvg[0], cpuInfo.LoadAvg[1], cpuInfo.LoadAvg[2])
// 输出不确定,所以不做验证
Click to show internal directories.
Click to hide internal directories.