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 d9bb4eb commit 13aa1b9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions system/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/mem"
"time"
)

type resource struct {
Expand All @@ -33,13 +34,13 @@ func (receiver *resource) ToString() string {

// GetResource 获取当前环境信息
func GetResource() *resource {
info, _ := cpu.Percent(0, false)
info, _ := cpu.Percent(time.Second, false)
infoStats, _ := cpu.Info()
memory, _ := mem.VirtualMemory()
hostInfo, _ := host.Info()
diskUsage, _ := disk.Usage("/")
if len(infoStats) == 0 {
infoStats = []cpu.InfoStat{cpu.InfoStat{}}
infoStats = []cpu.InfoStat{{}}
}
if len(info) == 0 {
info = []float64{float64(0)}
Expand Down

0 comments on commit 13aa1b9

Please sign in to comment.