Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DomainGetCPUStats param #92

Closed
fcddk opened this issue Jan 8, 2020 · 8 comments
Closed

DomainGetCPUStats param #92

fcddk opened this issue Jan 8, 2020 · 8 comments

Comments

@fcddk
Copy link

fcddk commented Jan 8, 2020

// DomainGetCPUStats is the go wrapper for REMOTE_PROC_DOMAIN_GET_CPU_STATS.
func (l *Libvirt) DomainGetCPUStats(Dom Domain, Nparams uint32, StartCPU int32, Ncpus uint32, Flags TypedParameterFlags) (rParams []TypedParam, rNparams int32, err error) {
}
Nparams ,StartCPU,TypedParameterFlags
How to finish the above three parameters?
And What can I get back? rParams ,rNparams

@trapgate
Copy link
Member

trapgate commented Jan 8, 2020

I'm not sure what you're asking here. If you're looking for help decoding the returned TypedParams, check in libvirt.go, there are some examples there that show how it's done. The returned rNparams value is redundant - len(rParams) will tell you the same thing..

@fcddk
Copy link
Author

fcddk commented Jan 9, 2020

Nparams ,StartCPU,TypedParameterFlags
How to finish the above three request parameters?

@fcddk
Copy link
Author

fcddk commented Jan 9, 2020

I don’t understand the meaning of these three parameters。

@trapgate
Copy link
Member

trapgate commented Jan 9, 2020

Your best resource for that question is the libvirt documentation for this function, which is here: https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetCPUStats

@fcddk
Copy link
Author

fcddk commented Jan 11, 2020

resultSli, _, err := l.DomainGetCPUStats(*domain, 1, -1, 1, 0)
if err != nil {
	log.Printf("failed to get domainCpuState: %v", err)
	return err
}
for _, value := range resultSli {
	fmt.Printf("cpuState: %v", value)
}

@fcddk
Copy link
Author

fcddk commented Jan 11, 2020

return:
cpuState: {cpu_time {4 1740335852754}}
cpuState: {cpu_time {4 663492372092}}
cpuState: {cpu_time {4 2788674600845}}
cpuState: {cpu_time {4 7265418187967}}
cpuState: {cpu_time {4 62431433010}}
cpuState: {cpu_time {4 20751254614}}
cpuState: {cpu_time {4 596372260237}}
cpuState: {cpu_time {4 233139094885}}

@fcddk
Copy link
Author

fcddk commented Jan 11, 2020

How does the data returned by the interface help me calculate CPU usage?

@vtolstov
Copy link

You must take two measurements.
After that substract from second measure first. Divide by number of seconds between two measurements.
Also note that stats for each cpu. So if you need total sum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants