This is a very simple statistics script that provides for services on/offline, memory info, server load averages and uptime and lastly drive info.
Its easily customised and i have usef <font> alot where you could have set come css and have it all done easily and look a bit more tidy than mine.
Simple server stats
<?
// Set the services you want the script to check.
// You can add more by just adding a line "servers name"=>"host/IP:port number",
// You can use game servers or anything.
// e.g. "IRCdaemon"=>"localhost:6667",
$services = array(
"http"=>"localhost:80",
"ssh"=>"localhost:22",
// "telnet"=>"localhost:23",
"ftp"=>"localhost:21",
// "smtp"=>"localhost:25",
"pop3"=>"localhost:110",
"mysql"=>"localhost:3306"
);
// Variables at the top of the page, date, uptime etc.
$date = date("l, M d, Y - h:i:s A");
$version = `uname -sr`;
$name = `hostname`;
$uptime = `uptime`;
// df command function, formatted into a table
function output_df()
{
$disk = `df`;
$lines = split("\n", $disk);
echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
{
$cols = preg_split("/[\s]+/", $lines[$i]);
if ($i == 0)
echo "<tr bgcolor=\"black\"><font color=orange>";
else
echo "<tr>";
for ($j = 0; $j < 6; $j++)
{
if ($j == 0 || $j == 5)
$align = "left";
else if ($j == 1 || $j == 2 || $j == 3)
$align = "right";
else if ($j == 4)
$align = "center";
echo "<td align=$align> <font face=\"Verdana\" size=\"1\" color=\"orange\">$cols[$j]</font> </td>";
}
echo "</font></tr>";
}
echo "</table>";
}
// free comand function, formatted into a table
function output_free()
{
$free = `free`;
$lines = split("\n", $free);
echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
{
if ($i == 2) $i++;
$cols = preg_split("/[\s]+/", $lines[$i]);
if ($i == 0)
echo "<tr bgcolor=\"black\">";
else
echo "<tr>";
foreach ($cols as $data)
echo "<td align=right> <font face=\"Verdana\" size=\"1\" color=\"orange\">$data</font> </td>";
echo "</tr>";
}
echo "</table>";
}
// info grabbind done, onto the html
?>
<table border="0" align="center" cellpadding="1" cellspacing="0">
<tr><td>
<p><font face="Verdana" size="1"><b>System Status:</b> <? echo $name ?><br><b>Time:</b> <? echo $date ?></font></p>
<font face="Verdana" size="1">
<? echo $version ?><br>
<? echo $uptime ?>
<p><table>
<b>Services:</b><br>
<tr bgcolor="black"><td><font face="Verdana" size="1" color="orange">Status</font></td><td><font face="Verdana" size="1" color="orange">Service</font></td><td><font face="Verdana" size="1" color="orange">Host</font></td></tr>
<?
foreach ($services as $name=>$location)
{
list($host, $port) = split(":",$location);
$running = fsockopen($host, $port, $errno, $errstr, 30);
if (!$running)
$status_color = "red";
else
{
fclose($running);
$status_color = "green";
}
echo "<tr><td align=center><div align=\"center\" style=\"font-size: 13pt; color: $status_color\" width=\"15\" height=\"15\"><b>?</b></div></td><td><font face=\"Verdana\" size=\"1\">$name</font></td><td><font face=\"Verdana\" size=\"1\">$host</font></td></tr>";
}
?>
</table></p>
<b>Memory:</b><br>
<? output_free(); ?><br>
<b>Drive Info:</b><br>
<? output_df(); ?>
</font>
</td></tr></table>
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.