<?
/*
This PHP script will show you how many space es aviable on your
Unix servers using df unix command
Tested on FreeBSD 4.x and 5.x
The attached file have the images for the graph
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Disk Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="100">Device</td>
<td width="100">Used Mb.</td>
<td width="100">Avial Mb.</td>
<td width="100">Mounted on</td>
<td>Graph
</td>
<td>Used %</td>
</tr>
<?
//Getting the information and pre filtering it
//the first grep cut the procfs that allways is show as 100% used
//the second one cut the header line
//next use awk to get only the wanted columns
//finally saving the data to a tmp file
exec("df -k | grep -v procfs|grep -v Filesystem|grep -v \"devfs\"|awk '{print $1\",\"$3\",\"$4\",\"$6\",\"$5}'>/tmp/df.tmp");
//reading the data to the memory from the file
$datos = file("/tmp/df.tmp");
//Cleaning Disk Space
unlink("/tmp/df.tmp");
for ($x=0;$x<sizeof($datos);$x++)
{
//spliting the info previusly saved with "," separatoy
list($device,$used,$remain,$mountpoint,$porcentaje) = split(",",$datos[$x]);
//Calculating the multiplier digit for the bar graph
$total = ($used + $remain);
$ajuste = ($remain/$total);
//Displaying the data
?>
<tr>
<td width="100" align="right"><?=$device;?> </td>
<!-- Convert the bytes in Mega bytes-->
<td width="100" align="right"><?=number_format(($used/1024),2);?> </td>
<td width="100" align="right"><?=number_format(($remain/1024),2);?> </td>
<td width="100" align="right"><?=$mountpoint;?> </td>
<!-- Make sure to change to the correct path for the images-->
<td><table width="150" height="15" border="0" align="center" cellpadding="0" cellspacing="0" background="img/barra_fondo.jpg">
<tr>
<td width="150" height="15" align="right"><img src="img/barra.gif" border="1" width="<?=(150 * $ajuste);?>" height="13"></td>
</tr>
</table>
</td>
<td> <?=$porcentaje;?></td>
</tr>
<?
}
//enjoy it...
?>
</table>
</body>
</html>