GithubHelp home page GithubHelp logo

Comments (5)

shirou avatar shirou commented on June 9, 2024

hmm. Could you show me your code?

When I run this code (26671 is some pid),

package main

import(
        "fmt"
        "time"

        "github.com/shirou/gopsutil/process"
)

func main(){
        p, err := process.NewProcess(26671)
        if err != nil{
                fmt.Println(err)
        }
        fmt.Println(p.CPUPercent(time.Second))
}

Result is

 31.991242461358688 <nil>

In same time top said

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                                        
26671 shirou    20   0  105764   2004   1012 R 33.0  0.3   0:11.67 sshd 

I tried other process, top said 0.3%, gopsutil said 0.6.

from gopsutil.

vrecan avatar vrecan commented on June 9, 2024
    cpuPercent, err := sys.proc.CPUPercent(time.Second)
    if nil != err {
            log.Error(err)
            return
    }
   fmt.Println(cpuPercent)

TOP

2834 persist+  20   0  628140   5896   4788 S   0.3  0.0   0:00.38 Vitals

Result

13.395245461338618

The only way I get stats that look right is to divide by 10. Then it's actually really close to correct. This system has 8 cores and 16 virtual cores running centos 7.

from gopsutil.

vrecan avatar vrecan commented on June 9, 2024

actually I have to do this:

    cpuPercent, err := sys.proc.CPUPercent(5 * time.Second)
    if nil != err {
            log.Error(err)
            return
    }
   fmt.Println(cpuPercent/10)

which makes no sense but seems to be really good.

from gopsutil.

shirou avatar shirou commented on June 9, 2024

I found my understanding about time delta in CPU percent. I fixed and tested using AWS instance. Could you try it again after go get -u?

from gopsutil.

vrecan avatar vrecan commented on June 9, 2024

That seems to have fixed it! Thanks. I really appreciate your library, making my life a lot easier. :)

from gopsutil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.