cpuutils

package
v0.0.0-...-98f1bff Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: Unlicense Imports: 7 Imported by: 0

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

func GetCPUInfo() (*CPUInfo, error)

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])

// 输出不确定,所以不做验证

Jump to

Keyboard shortcuts

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