<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Wow ... lots of questions.<br><br>I have done essentially the same thing you are asking ... but not in an automated way.<br><br>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.<br><br>Regarding being able to powerOn a Virtual machine programatically:  Yes.  This can be done via a couple ways:<br>1) Command-line utility: VBoxManage<br>2) SDK APIs (even exposed via webservices too)<br>Both the methods above provide extensive control of a VM and are not limited to only powering-on a virtual machine.<br><br>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).<br><br>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%.<br><br>Regarding Linux's caching:  In many cases ... to try and determine 'free' ... cached + free is the calculation that is used.<br><br>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.<br><br>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.<br><br><br>Joe<br><br></div><div style="font-family:
 times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Adrian Marogel <adrian.marogel@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> vbox-dev@virtualbox.org<br><b><span style="font-weight: bold;">Sent:</span></b> Sun, April 25, 2010 11:08:53 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [vbox-dev] VirtualBox monitor CPU usage of virtual machine<br></font><br>
<br>I asked you this because I've used before a vmware sdk and that had the first<br>two problems resolved in its API. I just wanted to know if this was possible<br>with VirtualBox.<br><br>I need an answer for the above, because I'm trying to run some distributed<br>calculations and use the following logic:<br>- I have a LAN of hosts running VirtualBox. I need to monitor the CPU usage of<br>the virtual machine's CPU and if that is above a certain threshold, say 90%,<br>then the next step would be to power on another virtual machine in the LAN,<br>after querying the hosts for available resources.<br><br>Do you have any ideas on how to accomplish this ? <br><br>Also, a fourth question, is there a way to limit the host's CPU usage by virtual<br>machines, so that if the virtual machine's CPU is 90%, the host CPU would be<br>much lower than that?<br><br><br>Note: I want to do all of these operations using the programmer approach, not<br>the sys-admin one, as
 I do want to write (Java) programs that would automate the<br>whole process.<br><br><br>My initial configuration is: <br>All hosts run Linux (Ubuntu) with Linux virtual machines, although they could<br>run Windows with Linux virtual machines.<br><br>My solution for this was the following: <br><br>Problem #1: I would SSH to login to the guest machine and then use an utility<br>like 'top' to monitor the CPU usage<br><br>Problem #2: I really haven't figured it out yet, because if I use the Linux<br>'free' utility, that doesn't guarantee that the returned result is accurate<br>enough for use. For example, on a system with 2 GB of memory, 'free' could<br>return that there are about 300mb left, because of all the caching done and the<br>system would still be able to power on a virtual machine that has 512mb of RAM.<br>So I don't really know how to resolve this issue.<br><br>Problem #3: I would also use SSH to login into the host machine and then
 use<br>something like VBoxManage for power on. Is there any functionality closer to<br>'teleporting' that would do this for me in VirtualBox or in the SDK?<br><br>Problem #4: I found some Linux program called CPULIMIT that would do the job. Is<br>there some other way I could do this?<br><br>For SSH logins, I would use the Ganymed Java library, for the remote execution<br>of programs.<br><br>But I still don't have ideas for Problem #2.<br><br>I posted the above to have a clearer idea about what I need to accomplish and<br>what solutions I came accross.<br><br>I'm waiting for your feedback, if you have other (more elegant) solutions.<br><br>Sincerely,<br>Adrian<br><br><br><br><br>_______________________________________________<br>vbox-dev mailing list<br><a ymailto="mailto:vbox-dev@virtualbox.org" href="mailto:vbox-dev@virtualbox.org">vbox-dev@virtualbox.org</a><br><span><a target="_blank"
 href="http://vbox.innotek.de/mailman/listinfo/vbox-dev">http://vbox.innotek.de/mailman/listinfo/vbox-dev</a></span><br></div></div>
</div><br>

      </body></html>