I was recently working in my lab environment that is constrained on resources. There were a couple VM’s that had High CPU once in a while and needed to be rebooted. They are just test VM’s but I still wanted to be able to catch when they spike the CPU and automate the reboot. In this guide I will show you how to monitor High CPU in any VM. What is nice is that it uses a hypervisor level monitor so there is no need for in guest agents or even VM tools.
Pre-Reqs
- A running vSphere environment with some VM’s that you have access to
- A running Aria Ops installaton that also has the vCenter Agent configured to monitor the above vSphere environment
- A test VM that you can run a script on to cause the CPU to spike
- A quite place where you will not be interrupted see my guide here
Login to Aria Operations and Configure the Alert
- Click Configure
- Click Alerts
- Click Alert Definitions
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png.jpeg)
Now Click Add
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-1.jpeg)
Edit the Alert Definition
- Give the Alert a name
- Enter a description
- Set the Base Object Type as Virtual Machine
- Click Next
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-2.jpeg)
Add a Condition
- Click Conditions
- Click Metrics
- Click CPU
- Drag and Drop Demand (%)
- Configure as shown
- Click Next
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-3-scaled.jpeg)
Select a recommendation
- Drag and drop any recommendations you would apply to fix the VM
- Click Next
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-4-scaled.jpeg)
Select the Policy you want this applied to.
Policies allow you to choose a subset of the vCenter Inventory. If you want all of vCenter just choose the vSphere Default Policy or you can create a specific one for a group of VM’s
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-5-scaled.jpeg)
Now login to either a linux or Windows VM to test this.
I am using a Photon OS 4 VM but you can use any Linux OS. Just make sure it is a test VM that you are ok spiking the CPU on.
You can get Photon OS here for free https://github.com/vmware/photon/wiki/Downloading-Photon-OS
Here is how to create the CPU spike script on Linux https://www.baeldung.com/linux/cpu-spike-bash
Here is how to create the CPU spike script on Windows https://winaero.com/how-to-create-100-cpu-load-in-windows-10/
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-6.jpeg)
Now start the cpu spike script with the following command
sh cpubusy.sh
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-7.jpeg)
Login to vCenter
Select the VM in the inventory and notice the CPU starting to rise
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-8-scaled.jpeg)
Go back to Aria Ops
- Click Troubleshoot
- Click Alerts
- Change to Scope
- Change to Virtual Machine
- Hit refresh until you see the alert for the VM you ran the CPUbusy script in
Note: It may take several minutes for the alarm to trigger
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-9-scaled.jpeg)
Go back to the VM you ran the CPUbusy script in and stop it
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-10.jpeg)
Go back to Aria Ops and click refresh until you see the alert disappear
Notice these alerts ar smart enough to go away if the condition is not there anymore
![1.png](https://www.vmtocloud.com/wp-content/uploads/2023/12/1-png-11-scaled.jpeg)