Is it possible to execute a command for eg:iostat inside a guest VM using libvirt or virsh .I want to find out IOPS for a guest vm but with libvirt java api I am not able to get the IOPS of a vm ,hence another method would be to execute a command like iostat inside a guest vm and take down the readings .
If you have set up a virtual serial console for your VM, you can use the
virsh consolecommand to connect to it.
You will have to use an
expectscript to login with username and password, run your command(s), extract the output, and then logout.
Note, though, that
expectis a single-purpose language and, IMO, there's no point in learning/using it if you don't already know it. You are much better off putting the time it would take to learn it into learning a general purpose language like
This has the added benefit that what you want to do will be a LOT easier with
pexpectmodule than with
expect's ability to extract data from the session is quite limited and primitive compared to what either
BTW, you mentioned
libvirt's Java API - a quick google search reveals that there are at least two different implementations of an
expect-like library for Java. There may be more.
I'm not a Java programmer, have never used either of these, have no idea if they're any good, and can not recommend one over the other.
Alternatively, if the VM has a network interface with an IP address and has
sshdinstalled (or you can install it), you can
sshinto the VM as you would any other host. This is, by far, the easiest and best way to do what you want.