Hello everyone,
I am an undergrad student. I find PowerCLI and VMware very interesting. And so, I am trying to do a small project in my last year of school.
Here's what I am trying to do-
1. Make a VM
2. Track (or keep a track of) its resources
3. As the resource usage goes beyong 75% or so, add more resources to it so that the VM wont crash.
That's it.
I know its a very vague idea. I have basic knowledge of PoweCLI (Making VMs, Linked clones, changing IPs of VMs through PCLI, reading/writing from/to a file) and of VMware(making hosts, clusters. VMs, Hot add).
I know all of you are really experienced and professionals in this field. I also wanna learn more and make my career in this field.
I googled a LOT about it. I read about VcloudAPI and healthnmon but I couldn't fit them with what I want to do.
If some of you all could direct me in the right direction, it would be great. Any help in this regard would be much much appreciated.
I need to finalize the project soon so if you think its "un-doable", please let me know so that I can select another one.
Thanks,
I think what you are trying to do, is perfectly possible.
A short example on how you could monitor CPU usage
$vmName = "MyVM"
$cpuThreshold = 75
$entity = Get-VM -Name $vmName
$stat = Get-Stat -Entity $vm -Stat cpu.usage.average -Realtime -MaxSamples 1
if (($stat | where {$_.Instance -eq ""} | Select -ExpandProperty Value) -gt $cpuThreshold){
Set-VM -VM $vm -NumCpu ($_.VM.NumCPU + 1) -Confirm:$false
}
You take 1 Realtime sample of the CPU usage.
When the aggregate value is above the threshold, you add a CPU.
See my PowerCLI & vSphere statistics – Part 1 – The basics post for more info on aggregates and instances.
The script assumes that you can dynamically add a CPU resource.
You can do something similar for memory consumption.
Now you have to decide how to schedule this script.
You can do that from your PowerCLI prompt with an endless loop, but scheduling the script via the Windows Task scheduler would be a lot more flexible.
See Alan's Running a PowerCLI Scheduled task for more details on that.
Now this is just the beginning, you would need to add some more functionality.
For example, the resources can't grow for ever, are you going to take away resources when the consumption goes below a specific threshold ?
Are you relying on 1 sample to make a decission, or wouldn't it be better to take an average over a period of time (for example 1 minute), before you make any changes ?
This to avoid one-off peaks in the consumption.
A very interesting topic you picked, you can really go very deep in this application.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow..
I wasn't expecting even a single reply.
Thanks a TON.
Its so glad to hear that its possible.
I will read the links that you suggested and will try to play around with the piece of script that you gave me.
And yes, my next question was going to be- can we remove resources from a VM? I tried to remove CPUs from a VM and I could not. So I thought I we can just add more CPUs and not take them off! Is that correct?
I will keep this thread updated.
Thanks a lot.
Afaik, vSphere supports a hot-add for CPU and memory (if all prereqs are met), but for a remove, you will have to power off the VM I'm afraid.
Which is logical in a way I guess.
Perhaps you can have a fixed time (during the night ?), to lower the number of resources.
You could for example, take the same Get-Stat but looks at the last hour or two.
If the resources are below the threshold, remove some.
A lot is possible, but you will have to first design and validate your basic process.
Once that is there, you can start the coding and fine-tuning parts.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So to tell you the truth, this thing started as a solution to a small problem that we were having in one of our class. We had to login on a machine (our user accounts were created there). And after 10 users, that particular machine used to slow down.
So that was the inspiration.
Now the other solution that I thought of was to check the resources and once its at 75%, make a new VM with the same user accounts on it and direct people on this new VM thereafter. And then once the number of users go zero on a machine, delete them.
Making and deleting a VM is easy but how would I make a new VM with the exact same users? Maybe I can make a linked clone. But then how would I direct new users to go on this new VM?
I can imagine many solutions to this, but none of these is quite simple.
One that comes to mind.
The logon script could go of and check how many active sessions there are on each of the VMs.
When it finds a VM that hasn't reached the maximum sessions yet, the logon will be redirected to that VM.
When none of the target VMs has a "free" session, the script would create a new VM, and redirects the logon to that one.
You could make the script pro-active, when the last logon was the maximum session, then it could already fire of the creation of a new VM.
You are in fact re-inventing Horizon View and the functionality of the Broker and the Connection servers :smileycool:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's amazing. That's the exact thing I want.
But could not understand how would I do the Logon script and how would this logon script direct users to a VM.
Are there some cmdlets for doing this? How can I do this? Can you please name a few cmdlets that I can learn more about which will help me do this?
Thanks ![]()
