vMetrics – Plugin for WordPress

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:

 

Latest version:

[download id=”22″]
[download id=”23″]

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

 

Previous versions

[download id=”16″]
[download id=”17″]

 

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.
Example configuration of Widget in sidebar

 

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]$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 = "http://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.
Example usage of the PowerCLI Updater script

 

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!

 

37 thoughts on “vMetrics – Plugin for WordPress”

  1. Hey Dan,

    Thanks!

    Unfortunately, there is no way to do that easily. Some development and modification of the plugin would be required (as well as the PowerCLI script). If you’re feeling confident with PHP you could give it a crack πŸ™‚ Of course, a single ESXi host would work on the current widget, but the power status is something you’d have to add a new field in for, and set up the plugin to handle (as well as create an entry in your wordpress DB that stores the value of the power status for the VM… all quite a lot to do!

    Sean

  2. Great script and worked first time.

    Is there anyway to monitor two seperate Vsphere ESXi boxes that are not linked and show them in seperate widgets? I assume if I run the script on both it would use the same key and mess up the stats?

    Also is there a easy way to collect the power status of a particular vm image? I.E I have a intranet with a list of servers on and I wanted to insert a nice icon status in a table next to each server name, so it collects separately for each and reports if that one is on, rather than all of the hosts.

    thanks

  3. Hey Cody,

    Many thanks! Glad to see your lab is up and running nicely! Come to think of it, I need to get my updater script rolling again – It stopped last time I moved house…

    Cheers
    Sean

  4. @Cody

    Not at all πŸ™‚ That would be much appreciated! I had a quick look at your site last night and must say the plugin looks great with that theme of yours! Best of luck with your blog : )

  5. @Cody

    Ah, I actually know what you mean now – that’s something I’ve seen happening and never bothered to fix. I need to handle the error with a try/catch perhaps. Thanks for pointing it out though! πŸ™‚

    Sean

  6. Hi Cody,

    Could you send the exact script you have along to me – link it as a dropbox download or something like that? Also, how are you executing or running the script to update the vMetric stats? I’ll see if I can reproduce the error myself and fix.

    Cheers
    Sean

  7. Hey Sean,

    Amazing plugin, i’ve been a huge fan since i first saw it running over at http://www.thehomeserverblog.com and i’ve wanted to integrate it onto a website ever since.

    I’m working on a “homelab” blog – nothing crazy, and got your plugin setup on it.

    The first run goes off without a hitch, but as it goes through and attempts to do metrics updates i start getting the following error…

    Cannot convert the “System.Net.HttpWebRequest” value of type “System.Net.HttpWebRequest” to type “System.Web.HttpRequest”. At mydirectoryobscured\vMetrics-updater\vMetrics-updater.ps1:161 char:2″

    Any thoughts?

  8. Thanks Mark πŸ™‚ If I do get around to updating the plugin I’ll definitely look to add that support. Thanks for the message!

    Sean

  9. Hi Sean,

    Awesome work on the plugin, I have it installed and working great. One thing that would be nice is support for multiple vCenters/Clusters. I have more than one cluster in my home lab and change things up pretty often.

    Thanks again for a fun way to view my lab stats!

  10. No problem πŸ™‚

    Well done on fixing the values in the DB. Don’t stress about the PowerCLI script – if I ever get a free day I’ll take a look myself!

  11. Hi Sean,

    Yes it does help, thanks for the quick reply btw πŸ™‚

    Somehow I’ve managed to fix it thanks to you pointing me in the right area in the database, and I didn’t destroy the database which is a bonus…

    There is very little chance I’ll be able to fix it… I’m not a coder and my powershell, php and MySQL skills are very very limited… However I do like a challenge and I will have a look and post my results if I get anywhere.

    Thanks Again πŸ™‚
    James

  12. Hi James,

    Thanks for the comment and feedback πŸ™‚

    You are correct, stats are indeed recorded in your WordPress MySQL DB. Check the wp_options table and you’ll find them all as vmetric_xxxx.

    I’ll check out the PowerCLI script if I get a chance at some point in the future, but my guess is that it is not handling the addition of figures correctly when looking at a single host. Thanks for pointing that out. If you do manage to fix the actual script itself, feel free to pastebin it and drop a link here in the comments for others to use πŸ™‚

    Hope that helps…

    Cheers!
    Sean

  13. Hey

    Love the plugin…

    I’ve hopefully got a quick question.

    I managed to get it working without any problems until I decided to point at a single host rather than a cluster. It’s now display the data from the cluster and the single host with the data added together. As much as I like it saying I’ve got twice the resources I really have I’d like it to show the correct data. πŸ™‚

    I’ve tried deleting the plugin and reinstalling it but I’m assuming the plugin data is stored in the wordpress database as it didn’t change… I did have a quick look to see if I could find it but I couldn’t πŸ™

    Any advice?

    Cheers
    James

  14. Hello
    I have edited the script in nano
    and run it with the following command ./vMetrics-updater.ps1
    was given error ./vMetrics-updater.ps1: line 1: syntax error: unexpected newline
    in what may be the problem?

  15. Hi Sean;

    Found your blog while looking for Microserver stuff. Have posted your vMetrics WP Plugin to our Microserver followers.

    Regards
    Joel

  16. Hi Josh,

    Excellent! Glad you got it sorted, and too true πŸ™‚ Your site is looking nice and clean, and the widget seems to fit in nicely! Nice one πŸ™‚

    Cheers,
    Sean

  17. Hey Sean,

    Figured it out! As I’ve come to realize in the tech field it’s always the simplest solution. I forgot I had a symlink to /var/www which is where I was adding the plugin. I was supposed to be placing it in /usr/share/wordpress/wp-content/plugin. Now it’s finally working! Hopefully this helps someone else so they realize the solution is extremely simple. If you want to check it out go to http://mrfechter.com/?page_id=5.

    Also one other thing that I spent a bit of time getting to work. When your using powercli to login and you type the username and pass in the command line window you need to escape special characters. I had a $ in my password and it kept erroring out. So after some searching on the web it turns out you need to escape special characters.

    Example:

    $Pass=my3xampl$pa$$ (this will error out and say incorect login details)
    $Pass=my3xampl`$pa`$`$ (this one will word correctly)

    Thanks again for the help! The plugin works great!

    -Josh

  18. Hey,

    Yea that is how I have it configured. I verified my permissions and I still see nothing on the plugins screen. I even renamed the akismet plugin in the directory for a test and that one disappeared from my installed plugin list, so it appears to be in the correct location. You can browse here and see the files look to be in the correct location, http://jfechter.com/wordpress/wp-content/plugins/. I’m still stumped by this issue. I tried various permissions but still nothing.

    Thanks

  19. Hey Josh,

    I just tested on WP 3.4.2 and can report it works fine for me. Very odd – so is the plugin currently sitting in your /wp-content/plugins directory? the full structure should therefore be blog.xyz/wp-content/plugins/vmetrics-plugin.

    In this directory, you should then have the vmetrics-plugin.php file and two folders: images and classes. I have the following permissions set on mine: vmetrics-plugin directory: 0755. vmetrics-plugin.php: 0644, images and classes directories: 0755. All files within the classes and images directories have permissions set at 0644. Perhaps try with those permissions and see if that works?

    Cheers,
    Sean

  20. Hello,

    Currently I’m running 3.4.2 so that could be part of the issue. Yup when I go to that location all I see is the akismet plugin which is in the same directory I placed the vmetrics-plugin folder. The permissions on the folder/files are 744 like the akismet plugin so I don’t believe that would be an issue. Thanks again for the help!

  21. Hey Joshua,

    What version of WordPress are you running? I have it tested on WordPress 3.4.1 at the moment… So under your plugins -> installed plugins section you don’t see it appearing there at all? Thanks for comment otherwise!

    Sean

  22. Hey,

    Your backup utility was amazing!!!!! Thanks for all your hard work. I am having an issue getting this plugin to show up in wordpress. It’s in my plugins directory in a folder called vmetrics-plugin. I changed permissions but wordpress still doesn’t see it. Any suggestions? Thanks again!

  23. Hey Ed,

    Thanks! That is a problem – hooking all the little utilities and extensions back into vCenter after a lab rebuild πŸ™‚ I am lucky to have the lab environment to the right – it is a work based though, so my actual home lab is a little more modest!

    Sean

  24. Nice work Sean! I was running Nick’s version for quite a while but I seem to rebuild my vCenter server frequently enough that I always forget to hook it back in afterwards. Looking at the stats on your blog you have a lab to be envious of!

Leave a Comment