vMetrics for WordPress
Display metrics from your VMware vCenter Cluster or ESX hosts / lab on your WordPress blog. Works with vSphere 4, 5 and 5.1.
Recently I have been looking for a small pet project to complete in bits of spare time, and have been wanting to do something that integrates with WordPress, yet relates to VMware. For quite some time now I have been using Nicholas Weaver’s (@lynxbat) excellent WP-vSphereStats plugin for WordPress on my blog. This displays some stats from your vCenter server or a ESX host as a widget on your blog.
I thought it would be an awesome little side project to revamp what he has done on the WordPress side (the actual plugin/widget) and create a new updater utility that is more flexible and customisable. In addition to this, I am also adding a bunch of new metrics some of which include HA and DRS statistics. The result of all this work is vMetrics for WordPress!
vMetrics is a small plugin for WordPress that works in conjunction with a PowerCLI Updater Script. You install the plugin, add the Widget to your sidebar in WordPress, configure which stats you would like to show, then run, or schedule the PowerCLI script against a standalong ESX/ESXi host, or vCenter server. This is much the same way that Nicholas’ utility works, but is now in PowerCLI format instead of an executable cmd line utility. This means it is very customisable, allowing you to modify the PowerCLI script and change which metrics come back. You could even modify the PHP plugin on WordPress’ side to allow any other metrics not already catered for in my release to show through on your own blog. Kudos to Nick for his excellent work – I couldn’t have done vMetrics without hacking apart and using a lot of his PHP code that he used to create his WP-vSphereStats WordPress plugin.
In addition to re-creating a new WordPress plugin and developing the PowerCLI Collector script, I have also designed some original icons relating to different VMware vSphere objects – Clusters, Hosts, VMs, CPU, RAM, NIC etc… I’ll post these up as high-res icons for download in a separate blog post. So without further ado, here are the WordPress plugin downloads:
Change log for version 1.1:
- Added new metrics section for hardware information (Model and Vendor of first host in cluster – this is editable in the PowerCLI script)
- Added configurable widget title section for Hardware
- Updated PowerCLI updater script to have a DO WHILE loop (allowing you to run the script once on a management machine and it will keep updating your blog vMetrics every 30 minutes. (The script is called once every half hour). Thanks @dawoo for the idea 🙂
- Added PowerCLI section to send the vendor and model type of the first ESX host it finds back to vMetrics so that you can display this information in the widget too
- Cleaned up PHP in main plugin code
WordPress Plugin Setup
- Download both files listed above.
- Extract the Plugin into your WordPress plugins directory. It should be named “vmetrics-plugin“
- Alternatively you can also upload the plugin .zip file using “Add new” from your plugins page in WordPress. If you get a “header error” when activating the plugin, just go direct to the plugins page and click “Activate” on the vMetrics plugin in that list – it should work via this method if the automatic activation after install doesn’t work.
- Login to WordPress, navigate over to Plugins, then “Activate” the vMetrics Plugin
- Go to Appearance -> Widgets in your admin page. Drag and drop the vMetrics Widget over to the relevant sidebar area you wish to display it on.
- Customise the Widget to your liking – you can change which sets of metrics about your vSphere environment are displayed, and which are not. Tick all the options you want to display, the click “Save“
- If you look in your admin left sidebar area, you will now notice a new entry called vMetrics Plugin – this has both main page and settings page sub menus. Select the Settings page.
- You will need to generate a “security key” that the PowerCLI updater script will use to validate itself with your WordPress plugin when it tries to connect and send the vMetric data back to WordPress.
- Generate a key, wait a few seconds for the page to refresh, then copy the key down into notepad for now.
PowerCLI Script setup
- Go to the workstation or vCenter server you wish to use to run the updater script. As long as you have PowerCLI installed and you are able to connect to your Host or vCenter from here, it will do fine.
- Copy the script over, and make sure it is not “blocked” (right click, properties, make sure “Unblock” has been done on the .ps1 file).
- Open the PowerCLI Script with notepad or your favourite PowerShell editor and update the very top section labelled “Customisable Variables“. This is the only bit of the script you need to change. You will need to enter your own blog and connection details as per the examples below:
- $WordpressURL -> Your WordPress blog URL and wordpress install. Enter exactly as it is, with no trailing slashes. For example: //www.shogan.co.uk
- $vCenter -> vCenter or ESX(i) host IP address or FQDN that the script will connect to, to fetch stats.
- $User -> your username to connect to host or vCenter
- $Pass -> your password
- [string]$ClusterToDisplay -> the exact name of the Cluster (if you have one) that you want to fetch metrics for. (Enter exactly as it appears in vCenter).
- [string]$authkey -> paste your security key you generated from the WordPress plugin here, exactly as it is, between the quotes.
- Save the PowerCLI script
- Example configuration of the script:
#region Customisable Variables $WordpressURL = "//www.mytechblogname.com" # Use the $vCenter variable for the ESX(i) Host address if you are only using one Host (otherwise use it for your vCenter server address). $vCenter = "192.168.60.10" $Username = "administrator" $Pass = "MySecurePass" # Only specify ClusterToDisplay if applicable - remember to deselect cluster # options such as DRS and HA in the WP Widget options if you are only using one host [string]$ClusterToDisplay = "MyMainClusterToGetStatsOn" [string]$authKey = "ddGeHucQLi3tD0LmgEGJ9IuCwfkoz5qn5zVokLC1Gu" #Make sure you enter this correctly - get the key from the plugin settings page! #endregion
Run the PowerCLI Script
- Open a PowerCLI console and make sure you are not already connected to any other hosts or vCenter servers (Disconnect-VIServer *)
- Navigate to folder containing your updater script
- Execute the script. Example .\vMetrics-Update.ps1
- All going well the script will connect to your vCenter/Host and collect various bits of information. It will then send this along to your plugin and update the metrics displayed on your blog.
- The script does not transmit your vCenter / ESX passwords!
- Remember you can also select which metrics are displayed in the widget settings.
- You can also schedule the script to run at a specific interval if you want – just use Windows Task Scheduler.
If you have any feedback, or have any issues please drop a comment below. I would also be interested to see how you customise your vMetrics stats or how you are using it on your own blog, so please do leave a comment below!