On this page
Xen and vserver: monitoring VMs on a PHP page
Introduction
I used this kind of script because it’s simpler to open a small web page to view VM activity rather than launching a bunch of commands.
Sudo
You need sudo because by default Apache doesn’t have the necessary rights to execute these commands:
apt-get install sudo
Then edit /etc/sudoers
and add the following:
www-data ALL=NOPASSWD: /usr/sbin/vserver-stat,/usr/sbin/xm list
Php and script
You obviously need to have Apache and PHP installed for this to work:
apt-get install apache2 php5
Additionally, there’s a small JavaScript that refreshes the page every 60 seconds.
Then create a folder and copy this into an index file:
mkdir /var/www/virtual && vi /var/www/virtual/index.php
Here’s the content of index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script language="javascript" type="text/javascript">
setTimeout("location.reload();", 600000);
</script>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<title>Informations for Virtual Machines</title>
</head>
<body>
<?php
system("date +%c") ;
echo("<BR><br />--- Vservers informations ---<br />") ;
echo("<syntaxhighlight lang="text"
>\n") ; system("sudo /usr/sbin/vserver-stat") ; echo("</syntaxhighlight
>\n") ; echo("<br />") ; echo("--- Xen informations ---<br />") ;
echo("<syntaxhighlight lang="text"
>\n") ; system("sudo /usr/sbin/xm list") ; echo("</syntaxhighlight
>") ; ?>
</body>
</html>
Now set the proper permissions:
chown -Rf www-data. /var/www/virtual
All that’s left is to access it :-)
Last updated 14 May 2007, 10:09 CEST.