Skip to content

Commit

Permalink
获取CPU的时间改成1秒
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Aug 30, 2024
1 parent 13aa1b9 commit 4ad98b9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions system/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

type resource struct {
type Resource struct {
OS string // 操作系统名称
Processes uint64 // 进程数
IP string // IP
Expand All @@ -28,12 +28,12 @@ type resource struct {
DiskUsagePercent float64 // 硬盘使用百分比
}

func (receiver *resource) ToString() string {
func (receiver *Resource) ToString() string {
return fmt.Sprintf("%+v", receiver)
}

// GetResource 获取当前环境信息
func GetResource() *resource {
func GetResource() Resource {
info, _ := cpu.Percent(time.Second, false)
infoStats, _ := cpu.Info()
memory, _ := mem.VirtualMemory()
Expand All @@ -45,7 +45,7 @@ func GetResource() *resource {
if len(info) == 0 {
info = []float64{float64(0)}
}
return &resource{
return Resource{
OS: hostInfo.OS,
Processes: hostInfo.Procs,
IP: net.GetIp(),
Expand Down

0 comments on commit 4ad98b9

Please sign in to comment.