Quick and dirty way of monitoring OpenStack Cluster with PHP script

I am using Ubuntu 12.04 I tried the script against the mysql database that folsom put together and its reporting things wrong. CHANGE THE SCRIPT to accommodate whatever you have setup.

So I don’t like zabbix. It seems complicated to me. I’d rather just hack something together in php. Add to it. Make it better. Get in contact with me, we can jam a little bit on it. If it were up to me I’d want to make it way nicer, if there was agents installed on the vms, I’d like to grab that data the agents report and populate another database so you can drill down and look at individual resource usage of vms. Now you will say, zabbix can do that. Ya, I don’t like zabbix. It seems so complicated to me.

Follow the steps below to a T.

I’m using ubuntu. (On a VM that is running apache or a box that is running apache that has access to the OpenStack database.)

1)apt-get install apache

2)apt-get install php5
3)apt-get install libapache2-mod-php5
4)apt-get install libapache2-mod-auth-mysql php5-mysql
5)/etc/init.d/apache2 restart

CHANGE MY SCRIPT TO REFLECT YOUR nova password, the $hostname variable at the top should be the ip address of the machine that houses your OpenStack mysql database.

After those changes are made take the .php file and put it in the following directory on your apache2 server: “/var/www/”

Navigate to http://IP_OF_DASHBOARD/resources.php

If you can’t see it right away,try to restart apache2 again. /etc/init.d/apache2 restart

######################

Script call it “resources.php”

Copy the script below to a file and name it “resources.php”

##########################

<?php

header(‘Refresh: 5′);
$end = array();

$username = “nova”;
$password = “FILL IN PASSWORD TO NOVA DATABASE HERE”;
$hostname = “FILL IN IP ADDRESS OF MYSQL DATABASE HERE”;

$dbhandle = mysql_connect($hostname, $username, $password)
or die(“Unable to connect to MySQL”);

$selected = mysql_select_db(“nova”,$dbhandle)
or die(“Could not select nova”);

$search = “select host,vcpus,vcpus_used,memory_mb,memory_mb_used,free_disk_gb,local_gb_used,running_vms from services, compute_nodes where compute_nodes.service_id=services.id;”;

$result = mysql_query($search);

echo “<br></br>”;
echo “<center><br>OpenStack Cluster Resources Usage.</br></center>”;

?>
<center>
<table border=’1’>
<tr>

<td>Host</td>
<td>vcpus</td>
<td>vcpus_used</td>
<td>memory_mb</td>
<td>memory_mb_used</td>
<td>free_disk_gb</td>
<td>local_gb_used</td>
<td>running_vms</td>
</tr>

<?php

while ($row = mysql_fetch_array($result)) {

echo “<tr>”;
echo “<td align=\”center\”>”.$row[host].”</td>”;
echo “<td align=\”center\”>”.$row[vcpus].”</td>”;
echo “<td align=\”center\”>”.$row[vcpus_used].”</td>”;
echo “<td align=\”center\”>”.$row[memory_mb].”</td>”;
echo “<td align=\”center\”>”.$row[memory_mb_used].”</td>”;
echo “<td align=\”center\”>”.$row[local_gb_used].”</td>”;
echo “<td align=\”center\”>”.$row[local_gb_used].”</td>”;
echo “<td align=\”center\”>”.$row[running_vms].”</td>”;
echo “</tr>”;
}
echo “</center>”;
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s