dommgifer
dommgifer

Reputation: 71

How can I get CPU usage of VM(KVM)

How can I get the cpu usage of vm in KVM like virt-manager? virt-manager monitoring vm cpu usage

Libvirt didn't provide API.

Does anyone know how to get vm cpu usage from host?

Upvotes: 2

Views: 14006

Answers (2)

Pupusa
Pupusa

Reputation: 197

If you use c or c++ you can try to look into virDomainGetCPUStats that is based on C API. However if you use Java, you won't get much luck.

Upvotes: 0

Fred Clift
Fred Clift

Reputation: 1043

If you have command-line access to the server, and you have the virsh command, you can use it to get stats.

There are several dom* subcommands that give you access to different things:

domifstat domain interface-device
       Get network interface stats for a running domain.

dommemstat domain [--period seconds] [[--config] [--live] | [--current]]
       Get memory stats for a running domain.


domstats [--raw] [--enforce] [--backing] [--state] [--cpu-total] [--balloon] [--vcpu] [--interface] [--block]
   [[--list-active] [--list-inactive] [--list-persistent] [--list-transient] [--list-running] [--list-paused]
   [--list-shutoff] [--list-other]] | [domain ...]
       Get statistics for multiple or all domains. Without any argument this command prints all available statistics for
       all domains.

So you might:

#virsh domstats --cpu-total server1
Domain: 'server1'
  cpu.time=144940157444
  cpu.user=65260000000
  cpu.system=14450000000

By polling that you can get the data you want.

Read the man page on virsh for more details.

edit: note that virsh is just a thin wrapper around the libvirt api - and this data is available via api calls also

Upvotes: 4

Related Questions