<html>
<head>
<title>PCH - Stats</title>
</head>
<body bgcolor="#dddddd">
<h1>PCH - Stats</h1>
<h2>Load & Uptime</h2>
<pre>
<?php
//GET SERVER LOADS
$loadresult = @exec("uptime");
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
//GET SERVER UPTIME
$uptime = explode(" up ", $loadresult);
$uptime = explode(",", $uptime[1]);
$uptime = $uptime[0].", ".$uptime[1];
// If uptime is <1day it will show a part of the load averages..
// This is a dirty fix
if ((substr($uptime,2,1)==":") OR (substr($uptime,3,3)=="min")) {
$uptime = substr($uptime,0,-21);
}
echo "<b>Load Averages:</b>\t".$avgs[1] .", ". $avgs[2] .", ". $avgs[3] ."\n";
echo "<b>Uptime:</b>\t\t".trim($uptime)."\n";
?>
</pre>
<hr width="300px" align="left" />
<h2>Disk usage</h2>
<pre>
<?php
$free = disk_free_space(".");
$total = disk_total_space(".");
$used = $total-$free;
function bytes2SI($bytes) {
$si_prefix = array( "B", "KiB", "MiB", "GiB", "TiB", "EiB", "ZiB", "YiB" );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
return sprintf("%1.2f" , $bytes / pow($base,$class)) . " " . $si_prefix[$class];
}
// Percentages
// number_format() ipv round() om bij ronde getallen
// bijkomende nullen achter de comma te zetten.
$usedperc = number_format($used*100/$total, 1);
$freeperc = number_format($free*100/$total, 1);
// Free & Total space
echo "<b>Total space:</b>\t" . bytes2SI($total) . "\t100 %\n";
echo "<b>Used space:</b>\t" . bytes2SI($used) . "\t".$usedperc . " %\n";
echo "<b>Free space:</b>\t" . bytes2SI($free) . "\t".$freeperc . " %\n";
?></pre>
<hr width="300px" align="left" />
<h2>Programs status</h2>
<pre>
<?php
function checkactive ($procesname) {
exec("ps aux | grep -i $procesname", $output);
if(is_dir("/share/Apps/".$procesname)) {
echo "\t<b>".$procesname."</b> is installed ";
if (count($output) > 2) { echo "and running.\n";}
else { echo "but NOT running.\n";}
}else {
echo "\t<b>".$procesname."</b> is NOT installed\n";
}
} // End of function checkactive
// ATTENTION: When adding other apps..
// use the foldername like in /share/Apps/
// the php function is_dir() for foldername IS CaSE SEnsItiVE
// the grep command uses the -i option to make it case-insentive
echo "<b>CouchPotato:</b>";
checkactive (couchpotato);
echo "<b>lighttpd:</b>";
checkactive (lighttpd);
echo "<b>NZBget:</b>\t";
checkactive (NZBget);
echo "<b>Sick Beard:</b>";
checkactive (sickbeard);
echo "<b>Telnetd:</b>";
checkactive (Telnetd);
echo "<b>Transmission:</b>";
checkactive (Transmission);
?></pre>
<hr width="300px" align="left" />
Go back <a href="/">Home</a>
</body>
</html>