Comments (5)
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.
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.
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.
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.
That seems to have fixed it! Thanks. I really appreciate your library, making my life a lot easier. :)
from gopsutil.
Related Issues (20)
- Weird data race HOT 1
- Information related to Model, Family and VendorID are unavailable for POWER9 and above.
- arch linux host version `"rolling"` -> `rolling` HOT 2
- [RFC] `winver.exe` output as platform version for windows hosts HOT 3
- Process.CreateTime reports incorrect or misleading time on Linux HOT 1
- host.Users() returns nil on macOS HOT 9
- windows's swap mem wrong
- cpu Mhz with current, max and min.
- Data race
- GPU Stats HOT 1
- macos tests failed on Github Action after latest image update
- Process information not reported for FreeBSD ARM64 HOT 1
- Can't compile for openbsd HOT 2
- When I call process.Percent,memory increase slowly
- proc.openfiles() crash HOT 1
- Monitor specific ports for network HOT 1
- v4 release plan HOT 1
- Is it possible to obtain the power of the whole machine? HOT 2
- Standart interfaces for services HOT 1
- Using host.HostID() on the Windows platform The uuid obtained is different from the cmd `wmic csproduct get uuid` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gopsutil.