[vbox-dev] VirtualBox monitor CPU usage of virtual machine

Joseph Smith joseph1962smith at yahoo.com
Sun Apr 25 20:46:13 GMT 2010


Wow ... lots of questions.

I have done essentially the same thing you are asking ... but not in an automated way.

I am not a Sun developer so will defer any final answers to someone on the Sun development team as they may have recommendations that are better than the suggestions I will provide below.

Regarding being able to powerOn a Virtual machine programatically:  Yes.  This can be done via a couple ways:
1) Command-line utility: VBoxManage
2) SDK APIs (even exposed via webservices too)
Both the methods above provide extensive control of a VM and are not limited to only powering-on a virtual machine.

I do not quite understand why you would want to check the virtual machine's stats of what it thinks the CPU usage is.  It would seem a more realistic way to check is the VMs cpu usage as seen by the host ... especially if you use CPU limit to set a max-limit for the VM's pid.  On the host, the CPU usage for each VM would be the individual task usage for the pid for that VM.  Also ... If you use cpulimit to ensure the VM does not consume more than say 50% of your host CPU, the actual CPU usage inside the VM looks quite different then the CPU usage of the pid for the VM on the host.  In fact ... by using cpulimit, especially if you set a low limit, your VM's CPU (meaning if you run top inside the VM) will show your CPU almost never idle (meaning nearly 100% busy).

If you would like to trigger starting a new VM, I would suggest you forget about the CPU usage inside the VM and look at how much CPU the VM task on the host is using.  That way, when you do your checking, if you use cpulimit to set a max limit of say 55%, you can factor that into your calculation to determine if it's time to start a new VM ... this time your threshold comparison would be say 45% instead of 90%.

Regarding Linux's caching:  In many cases ... to try and determine 'free' ... cached + free is the calculation that is used.

Not sure I see how teleporting fits into the scheme of things.  Unless mistaken .. .at least the way I use it ... Teleporting is a convenient way of moving an executing VM from one host to another host (as long as they share virtual disk resources).  This is convenient if you needed to maybe take a host off-line to add more physical memory, etc ... and so you could teleport all the VMs on that host to another system without interrupting the operations they are performing.  This could also be used as a form of load-balancing where a process was started on a VM that was too CPU intensive and you could then teleport the running VM to a 'less busy' host.  From your request ... it seems you need to start a new VM instance to help with accepting part of the workload ... so moving the VM via teleporting would not seem to help ...unless as I noted the host itself was being pegged.

May I suggest one thing:  Rather than ssh'ing into the remote systems ... which would require you to set-up log-ins for users ... and configuring permissions so no-one could accidentally execute something that could be a security risk ... why not write a webservice that would simply accept a request and return all the data you need: e.g: CPU usage, Memory usage, Disk usage, top N tasks using more than say 20%CPU, etc.  This way, no extra authentication would be required.  If security is an issue ... just use SSL with a cert that only you administer.  This would only require either a webserver or a small utility to run to accept the connection.  But that's just my thought.


Joe





________________________________
From: Adrian Marogel <adrian.marogel at gmail.com>
To: vbox-dev at virtualbox.org
Sent: Sun, April 25, 2010 11:08:53 AM
Subject: Re: [vbox-dev] VirtualBox monitor CPU usage of virtual machine


I asked you this because I've used before a vmware sdk and that had the first
two problems resolved in its API. I just wanted to know if this was possible
with VirtualBox.

I need an answer for the above, because I'm trying to run some distributed
calculations and use the following logic:
- I have a LAN of hosts running VirtualBox. I need to monitor the CPU usage of
the virtual machine's CPU and if that is above a certain threshold, say 90%,
then the next step would be to power on another virtual machine in the LAN,
after querying the hosts for available resources.

Do you have any ideas on how to accomplish this ? 

Also, a fourth question, is there a way to limit the host's CPU usage by virtual
machines, so that if the virtual machine's CPU is 90%, the host CPU would be
much lower than that?


Note: I want to do all of these operations using the programmer approach, not
the sys-admin one, as I do want to write (Java) programs that would automate the
whole process.


My initial configuration is: 
All hosts run Linux (Ubuntu) with Linux virtual machines, although they could
run Windows with Linux virtual machines.

My solution for this was the following: 

Problem #1: I would SSH to login to the guest machine and then use an utility
like 'top' to monitor the CPU usage

Problem #2: I really haven't figured it out yet, because if I use the Linux
'free' utility, that doesn't guarantee that the returned result is accurate
enough for use. For example, on a system with 2 GB of memory, 'free' could
return that there are about 300mb left, because of all the caching done and the
system would still be able to power on a virtual machine that has 512mb of RAM.
So I don't really know how to resolve this issue.

Problem #3: I would also use SSH to login into the host machine and then use
something like VBoxManage for power on. Is there any functionality closer to
'teleporting' that would do this for me in VirtualBox or in the SDK?

Problem #4: I found some Linux program called CPULIMIT that would do the job. Is
there some other way I could do this?

For SSH logins, I would use the Ganymed Java library, for the remote execution
of programs.

But I still don't have ideas for Problem #2.

I posted the above to have a clearer idea about what I need to accomplish and
what solutions I came accross.

I'm waiting for your feedback, if you have other (more elegant) solutions.

Sincerely,
Adrian




_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
http://vbox.innotek.de/mailman/listinfo/vbox-dev



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20100425/0698a37b/attachment.html>


More information about the vbox-dev mailing list