vMetrics 1.2 Plugin for WordPress – Multiple Cluster Edition
13th July 2015I have been a fan of both Nick Weaver’s WP-vSphereStats and Sean Duffy’s fork of that – vMetrics Plugin for WordPress but one of the things missing from vMetrics was additional Clusters.
I asked on Twitter if anyone knew how to add that functionality in and Sean kindly responded saying it was hard coded to the WordPress plugin’s PHP but if I had the inclination I could have a look and see if I could add the required functionality, now I should add that I am not a coder, so it was with a little hesitation that I started to look at the code.
I am pleased to say however that it only took me a couple of hours to butcher Sean’s excellent work to make it display a second cluster, it’s not pretty but it does work.
Browsing the code should make it fairly obvious what I did to allow me to show a second cluster and I don’t see any issues with adding additional clusters to the output, follow the same train of thought (or if you can do it better) and please let me know (after all, who doesn’t want better \ improved code).
Please note that I had to make changes to both the WordPress plugin as well as the PowerCLI Updater script, again fairly obvious changes but it works.
With regards to installation, you should be ok to just over write your existing plugin, if you’re starting from scratch do a manual installation using either the zip file or by directly uploading the extracted files to your plugins folder.
Change log for version 1.2:
- Added additional metrics section for second cluster information
- Updated PowerCLI updater script to allow you to gather and upload second cluster information.
- Completely made a mess of the previously cleaned up PHP in main plugin code, it’s a mess but it works.
I am making this available to anyone that want’s it, I have given credit to both Nick Weaver and Sean for their earlier work and ask that anyone moving this forward does the same please.
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. You will get a “header error” when activating the plugin directly after installation so just go direct to the plugins page and click “Activate” on the vMetrics plugin in that list.
- 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: http://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]$ClusterToDisplay1 -> the exact name of the first Cluster (if you have one) that you want to fetch metrics for. (Enter exactly as it appears in vCenter).
- [string]$ClusterToDisplay2 -> the exact name of the second 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.
I use a batch file via Task Scheduler to update my stats:-
Powershell -psconsolefile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& ‘C:\Temp\vMetrics-updater\vMetrics-updater.ps1’"
Warning, if you only have a single cluster don’t bother downloading this update because the Cluster 2: section will be present regardless