shirou / gopsutil

psutil for golang
Other
10.56k stars 1.58k forks source link

Getting all 0 for cpu.Percent on Centos #579

Closed subbu05 closed 4 years ago

subbu05 commented 6 years ago
package main

import (
    "fmt"

    "github.com/shirou/gopsutil/cpu"
    "time"
)

func main() {

    percent,_ := cpu.Percent(time.Second,true)
    fmt.Println(percent)
    //fmt.Printf("CPU_Usage(percentage)-User:%.2f Nice:%.2f Sys:%.2f Intr:%.2f Idle:%.2f States:%.2f",percent[0],percent[1],percent[2],percent[3],percent[4],percent[5])
}

Output [0 0 0 0]

cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@5b318c987c94 /]# uname -a
Linux 5b318c987c94 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
josueneo commented 6 years ago

Have you tried to put some load onto the OS and see some real cpu usage?

subbu05 commented 6 years ago

Yes with load I see all 0's Also the array size is 4 instead 5.

josueneo commented 6 years ago

The output is only 1 total usage for each cpu core, which in your case is 4 cores.

I will test tomorrow in a centos vm.

Lomanic commented 6 years ago

Also the array size is 4 instead 5.

How many cores are returned by cpu.Info or cpu.Counts?

subbu05 commented 6 years ago

I have mac with 4 core CPU.

Lomanic commented 5 years ago

cpu.Percent gets its data from /proc/stat (via cpu.Times()), can you paste its content here? Thanks in advance.

The number of cores seems right to me by the way.

Lomanic commented 5 years ago

@subbu05 I would appreciate if you could report the result of the following https://github.com/shirou/gopsutil/issues/568#issuecomment-446009859

Lomanic commented 4 years ago

No news from reporter.