WP-XenServerStats – WordPress Plugin for XenServer 1/2
WP-XenServerStats – WordPress Plugin for XenServer 2/2
In the first part of this blog, I made a list about what I wanted to do, how to get the data and how to transport it from my XenServer (home) to my Web Host (Datacenter). Now I’ll explain how I create one WordPress plug-in (my first one) to show everything :
It looks good, and even if it’s really low level on the dev side in PHP and scripting, it works well. In WordPress, there is this sidebar, on the right, if you want to add something you can chose to do it as widget, it’s clean and not hard coded in the main WordPress code, then you can easily keep this plug-in and keep it working without changing anything from a theme to another.
I created a file named : wp-xenserverstats.php in a new directory : wp-xenserverstats/wp-xenserverstats.php this is the main plug-in file and as you can read bellow, this is very very basic.
- <?php
- /*
- Plugin Name: WP-XenServerStats
- Plugin URI:
- Description: Citrix XenServer statistics
- Version: 0.2
- Author: Stephane Thirion
- Author URI:
- */
-
- function xenserverhostname()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/hostname.txt";
- echo $theData;
- }
-
- function hostcpu()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/host_cpus.txt";
- echo $theData;
- }
-
- function hostmem()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/host_mem.txt";
- echo $theData;
- }
-
- function totalvmscount()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/vms_total.txt";
- echo $theData;
- }
-
- function totalpoweredvmscount()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/vms_powered.txt";
- echo $theData;
- }
-
- function totalhaltedvmscount()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/vms_halted.txt";
- echo $theData;
- }
-
- function totalsuspendedvmscount()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/vms_suspended.txt";
- echo $theData;
- }
-
- function lastupdate()
- {
- $myFile = "/homez.35/archy/www/wp-content/plugins/wp-xenserverstats/last_update.txt";
- echo $theData;
- }
-
- function widget_wpxenserver($args)
- {
- echo $before_widget;
- echo $before_title;
- echo "XenServer Stats";
- echo $after_title;
- echo "<div style='text-align: left; padding-left: 10px;'><b><u><img src='".$baseurl."/wp-content/plugins/wp-xenserverstats/images/host.png'> Host : ";
- xenserverhostname();
-
- echo "</u></b><br>Cpu Nbr : ";
- hostcpu();
-
- echo "/ Memory : ";
- hostmem();
-
- echo "Mb<br><br><img src='".$baseurl."/wp-content/plugins/wp-xenserverstats/images/vmstotal.png'> Virtual Machines : ";
- totalvmscount();
-
- echo "<br><img src='".$baseurl."/wp-content/plugins/wp-xenserverstats/images/powered.png'> Powered On VMs : ";
- totalpoweredvmscount();
-
- echo "<br><img src='".$baseurl."/wp-content/plugins/wp-xenserverstats/images/halted.png'> Halted VMs : ";
- totalhaltedvmscount();
-
- echo "<br><img src='".$baseurl."/wp-content/plugins/wp-xenserverstats/images/paused.png'> Suspended VMs : ";
- totalsuspendedvmscount();
-
- echo "<br><br><i>Last Update : ";
- lastupdate();
-
- echo "</i></div>";
- echo $after_widget;
- }
-
- function wpxenserver_init()
- {
- register_sidebar_widget(__('XenServer Widget'), 'widget_wpxenserver');
- }
- add_action("plugins_loaded", "wpxenserver_init");
- ?>
So as you see, there is still some hard coded path… I try to get rid of that this week, and if someone can give me the tip, it will save me some time… (more…)