Data is being collected:
LoadAVG is running however there is insufficient data at the moment to draw the charts.
Please try reloading this page in 10-15 minutes.";
//exit;
}
// ---------------------------------------------------------------------------
// Run through the data once to set some minimum and maximum values.
if ($m && $vps) {
$oomgmax = "1";
$oomgmin = "99999999";
$oomgsum = 0;
$privmax = "1";
$privmin = "99999999";
$privsum = 0;
}
else {
$memmax = "1";
$memmin = "99999999";
$loadmax = "0.01";
$loadmin = "100";
$loadsum = 0;
$txmin = "99999999";
$rxmin = "99999999";
$txmax = "0.01";
$rxmax = "0.01";
}
//predefining these variables
$memsum = 0;
$txsum = 0;
$rxsum = 0;
foreach($fc as $line) {
$line = trim($line);
$parts = explode('|',$line);
if (!$m) {
$ld_parts = explode(",",$parts[1]);
if ($ld_parts[$ld] > $loadmax) { $loadmax = $ld_parts[$ld]; $loadmaxstamp = $parts[0]; }
if ($ld_parts[$ld] < $loadmin) { $loadmin = $ld_parts[$ld]; $loadminstamp = $parts[0]; }
$loadlast = $ld_parts[$ld];
$loadsum = $loadsum + $ld_parts[$ld];
}
if ($m && $vps) {
if ($parts[2] > $oomgmax) { $oomgmax = $parts[2]; $oomgmaxstamp = $parts[0]; }
if ($parts[2] < $oomgmin) { $oomgmin = $parts[2]; $oomgminstamp = $parts[0]; }
if ($parts[3] > $privmax) { $privmax = $parts[3]; $privmaxstamp = $parts[0]; }
if ($parts[3] < $privmin) { $privmin = $parts[3]; $privminstamp = $parts[0]; }
$oomglast = $parts[2];
$oomgsum = $oomgsum + $oomglast;
$privlast = $parts[3];
$privsum = $privsum + $privlast;
}
elseif ($vps) {
if ($parts[3] > $memmax) { $memmax = $parts[3]; $memmaxstamp = $parts[0]; }
if ($parts[3] < $memmin) { $memmin = $parts[3]; $memminstamp = $parts[0]; }
$memlast = $parts[3];
$memsum = $memsum + $memlast;
}
else {
if ($parts[2] > $memmax) { $memmax = $parts[2]; $memmaxstamp = $parts[0]; }
if ($parts[2] < $memmin) { $memmin = $parts[2]; $memminstamp = $parts[0]; }
$memlast = $parts[2];
$memsum = $memsum + $memlast;
}
if (!$m) {
if ($parts[4] > $txmax && $parts[4] !== 'x') { $txmax = $parts[4]; $txmaxstamp = $parts[0]; }
if ($parts[4] < $txmin && $parts[4] !== 'x' && $parts[4] >= 0) { $txmin = $parts[4]; $txminstamp = $parts[0]; }
if ($parts[5] > $rxmax && $parts[5] !== 'x') { $rxmax = $parts[5]; $rxmaxstamp = $parts[0]; }
if ($parts[5] < $rxmin && $parts[5] !== 'x' && $parts[5] >= 0) { $rxmin = $parts[5]; $rxminstamp = $parts[0]; }
$txlast = $parts[4];
$rxlast = $parts[5];
if ($txlast >= 0)
$txsum = $txsum + $parts[4];
if ($rxlast >= 0)
$rxsum = $rxsum + $parts[5];
}
$last = $parts[0];
} // close foreach()
// ---------------------------------------------------------------------------
// Stuff we need to do now (that we don't do for each iteration).
if (!$m) {
$memrange = $memmax - $memmin;
$memmid = $memmin + ($memrange/2);
$loadrange = $loadmax - $loadmin;
$loadmid = number_format(round($loadmin + ($loadrange/2),2),2);
// for tx/rx charts
$txfactor = 100/$txchart;
$txmid = $txchart/2;
$rxfactor = 100/$rxchart;
$rxmid = $rxchart/2;
}
else {
$oomgrange = $oomgmax - $oomgmin;
$oomgmid = $oomgmin + ($oomgrange/2);
$privrange = $privmax - $privmin;
$privmid = $privmin + ($privrange/2);
}
// ---------------------------------------------------------------------------
// Go through data again, this time producing HTML output.
$loadcols = $loadtime = $memcols = $memtime = $txcols = $txtime = $rxcols = $rxtime = "";
$hour = $minute = 0;
foreach($fc as $line) {
$last_hour = $hour;
$last_minute = $minute;
$line = trim($line);
if ($line == "") continue;
$parts = explode('|',$line);
$timestamp = $parts[0];
/*$diff = $timestamp - $last_timestamp;
if ($last_timestamp && ($timestamp - $last_timestamp < 150))
{
continue;
}
else
$last_timestamp = $timestamp;*/
if (!$m) {
$ld_parts = explode(",",$parts[1]);
$load = $ld_parts[$ld];
if ($vps) {
$mem = $parts[3];
}
else {
$mem = $parts[2];
}
$txbytes = $parts[4];
$rxbytes = $parts[5];
}
else {
$oomg = $parts[2];
$priv = $parts[3];
}
$datetime = date("g:i a",$timestamp);
// echo $datetime." - ".$line."
";
$minute = abs(date("i",$timestamp));
$hour = date("G",$timestamp);
$gap = false;
if ($last_hour + 1 < $hour && $last_hour > 0)
{
list($loadcols,$loadtime) = drawblankinitially($loadcols, $loadtime, $last_hour, $hour);
list($memcols,$memtime) = drawblankinitially($memcols, $memtime, $last_hour, $hour);
list($rxcols,$rxtime) = drawblankinitially($rxcols, $rxtime, $last_hour, $hour);
list($txcols,$txtime) = drawblankinitially($txcols, $txtime, $last_hour, $hour);
$last_minute = 0;
$gap = true;
}
// if ($last_minute > 50) $last_minute = 0;
$diff_minute_last_minute = $minute - $last_minute;
if ($diff_minute_last_minute > 3 && $loadcols)
{
$fill = floor($diff_minute_last_minute / 3) - 1;
for ($f = 0; $f < $fill;$f++)
{
$loadcols .= "\n";
$memcols .= "\n";
$rxcols .= "\n";
$txcols .= "\n";
}
}
//echo $diff_minute_last_minute;
// chart the load average.
if (!$m) {
$loaddiff = $load - $loadmin;
$loadheight = $loadrange ? ceil($loaddiff/$loadrange*100) : $loaddiff;
if ($load < $load_yellowline) { $loadclass = 'gr'; }
elseif ($load < $load_redline) { $loadclass = 'yl'; }
else { $loadclass = 'rd'; }
// Hack for IE which can't correctly align a 1px high box...
if ($loadheight == 1) { $loadheight = 2; }
if ($loadheight == 0) { $loadheight = 2; $loadclass = 'wh'; }
// --
$loadtop = 100-$loadheight;
if ($loadcols == "") {
if ($hour > 0)
{
for ($c = 0;$c<$hour;$c++)
{
$loadcols.= "\n | ";
$t = "";
if ($c%2==0) $t = $c;
$loadtime.= "\n".$t." | ";
}
}
if ($minute < 2)
{
$loadcols .= "\n\n";
if (is_int($hour/2))
{
if ($hour == 0)
$loadtime .= "\n | $hour | ";
else
$loadtime .= "\n$hour | ";
}
}
else
{
if (is_int($hour/2))
$loadtime .= "\n$hour | ";
$loadcols .= "\n\n";
for ($c = 0; $c < $minute;$c=$c+6)
$loadcols .= "\n";
$loadcols .= "\n";
}
}
elseif ($loadcols && ($minute < 2 || $gap)) {
if (!$gap)
$loadcols .= "\n | \n\n";
if (is_int($hour/2)) {
$loadtime .= "\n | $hour | ";
}
}
else {
$loadcols .= "\n";
}
// chart memory (privvmpages for VPS) or 'used memory' on a dedicated.
list($memcols,$memtime) = chartmem($memcols,$memtime,$mem,$memmax,$memmin,$memmid,$memrange,$oomgbarrier,$privbarrier,$hour,$minute,$timestamp,$last,$gap);
// chart transmit rate.
// bytes = 'x' when the interface is not found (incorrect $eth setting).
if ($rxbytes == 'x') { $rxbytes = 0; }
if ($txbytes < 0) $txbytes = 0;
if ($txbytes >= $txchart) {
$txheight = 100;
$txtop = 0;
$txclass = 'bl';
$txbighour = 'txbig'.$hour;
$$txbighour .= $txbytes .' ';
}
else {
$txheight = ceil($txbytes/$txchart*100);
$txtop = 100-$txheight;
$txclass = 'gr';
}
// echo $txbytes;
// Hack for IE...
if ($txheight == 1) { $txheight = 2; $txtop = 98; }
if ($txheight == 0) { $txheight = 2; $txtop = 98; $txclass = 'wh'; }
// --
if ($txcols == "")
{
if ($hour > 0)
{
for ($c = 0;$c<$hour;$c++)
{
$txcols.= "\n";
$t = "";
if ($c%2==0) $t = $c;
$txtime.= "\n | ".$t." | ";
}
}
if ($minute < 2)
{
$txcols .= "\n\n";
if (is_int($hour/2))
{
if ($hour == 0)
$txtime .= "\n | $hour | ";
else
$txtime .= "\n$hour | ";
}
}
else
{
if (is_int($hour/2))
$txtime .= "\n$hour | ";
$txcols .= "\n\n";
for ($c = 0; $c < $minute;$c=$c+6)
$txcols .= "\n";
$txcols .= "\n";
}
}
elseif ($txcols && ($minute < 2 || $gap)) {
if (!$gap)
$txcols .= "\n | \n\n";
if (is_int($hour/2)) {
$txtime .= "\n | $hour | ";
}
}
else {
$txcols .= "\n";
}
// chart receive rate.
// bytes = 'x' when the interface is not found (incorrect $eth setting).
if ($rxbytes == 'x') { $rxbytes = 0; }
if ($rxbytes < 0) $rxbytes = 0;
if ($rxbytes >= $rxchart) {
$rxheight = 100;
$rxtop = 0;
$rxclass = 'bl';
$rxbighour = 'rxbig'.$hour;
$$rxbighour .= $rxbytes .' ';
}
else {
$rxheight = ceil($rxbytes/$rxchart*100);
$rxtop = 100-$rxheight;
$rxclass = 'gr';
}
// Hack for IE...
if ($rxheight == 1) { $rxheight = 2; $rxtop = 98;}
if ($rxheight == 0) { $rxheight = 2; $rxtop = 98; $rxclass = 'wh'; }
// --
if (!$rxcols) {
if ($hour > 0)
{
for ($c = 0;$c<$hour;$c++)
{
$rxcols.= "\n";
$t = "";
if ($c%2==0) $t = $c;
$rxtime.= "\n | ".$t." | ";
}
}
if ($minute < 2)
{
$rxcols .= "\n\n";
if (is_int($hour/2))
{
if ($hour == 0)
$rxtime .= "\n | $hour | ";
else
$rxtime .= "\n$hour | ";
}
}
else
{
if (is_int($hour/2))
$rxtime .= "\n$hour | ";
$rxcols .= "\n\n";
for ($c = 0; $c < $minute;$c=$c+6)
$rxcols .= "\n";
$rxcols .= "\n";
}
}
elseif ($rxcols && ($minute < 2 || $gap)) {
if (!$gap)
$rxcols .= "\n | \n\n";
if (is_int($hour/2)) {
$rxtime .= "\n | $hour | ";
}
}
else {
$rxcols .= "\n";
}
} // close if(!$m)
else {
list($oomgcols,$oomgtime) = chartmem($oomgcols,$oomgtime,$oomg,$oomgmax,$oomgmin,$oomgmid,$oomgrange,$oomgbarrier,$privbarrier,$hour,$minute,$timestamp,$last,$gap);
list($privcols,$privtime) = chartmem($privcols,$privtime,$priv,$privmax,$privmin,$privmid,$privrange,$oomgbarrier,$privbarrier,$hour,$minute,$timestamp,$last,$gap);
}
} // close foreach()
// --------------------------------------------------------------------
// Various formatting for display, including table completion (blank
// hours), mouseovers for out-of-range data on tx & rx charts, the
// logfile select form, number formatting, etc.
// not sure if tis is the right way to ddo this!
if (!$m) {
for ($i=0; $i<24; $i++) {
// tx/rx out-of-range mousovers.
$txbignum = 'txbig'.$i;
$rxbignum = 'rxbig'.$i;
if ($$txbignum) {
$tbiglist = trim($$txbignum);
$tbiglist = str_replace(' ',', ',trim($tbiglist));
$tstr = " title=\"Values off-chart: ".$tbiglist."\" style='cursor:help'";
$txcols = str_replace(" TXBIG_$i",$tstr,$txcols);
$txmouse =TRUE;
}
if ($$rxbignum) {
$rbiglist = trim($$rxbignum);
$rbiglist = str_replace(' ',', ',trim($rbiglist));
$rstr = " title=\"Values off-chart: ".$rbiglist."\" style='cursor:help'";
$rxcols = str_replace(" RXBIG_$i",$rstr,$rxcols);
$rxmouse = TRUE;
}
}
$txcols = preg_replace("/ TXBIG_[0-9]{1,2}/", "", $txcols);
$rxcols = preg_replace("/ RXBIG_[0-9]{1,2}/", "", $rxcols);
list($loadcols,$loadtime) = drawblank($loadcols,$loadtime,$hour,$logfile);
list($memcols,$memtime) = drawblank($memcols,$memtime,$hour,$logfile);
list($txcols,$txtime) = drawblank($txcols,$txtime,$hour,$logfile);
list($rxcols,$rxtime) = drawblank($rxcols,$rxtime,$hour,$logfile);
// Info for the summary panes.
$loadmax = number_format(doubleval($loadmax),2);
$loadmin = number_format(doubleval($loadmin),2);
$loadmaxtime = date("g:ia", $loadmaxstamp);
$loadmintime = date("g:ia", $loadminstamp);
if($cnt > 0)
$loadmean = number_format (round(($loadsum/$cnt),2),2);
if ($vps) {
$memmax = number_format(round(($memmax/256),1),1);
$memmin = number_format(round(($memmin/256),1),1);
$memmid = number_format(round(($memmid/256),1),1);
$memmean = ($memsum/$cnt);
$memmean = number_format(round(($memmean/256),1),1);
$memlast = number_format(round(($memlast/256),1),1);
$oomgbarriermb = round($oomgbarrier/256);
$burstlimit = round($privbarrier/256);
$burstwarn = round($burstlimit*.75);
}
else {
$memmax = number_format(round(($memmax/1024),1),1);
$memmin = number_format(round(($memmin/1024),1),1);
$memmid = number_format(round(($memmid/1024),1),1);
if($cnt > 0)
$memmean = ($memsum/$cnt);
$memmean = number_format(round(($memmean/1024),1),1);
$memlast = number_format(round(($memlast/1024),1),1);
}
$memmaxtime = date("g:ia", $memmaxstamp);
$memmintime = date("g:ia", $memminstamp);
$txmax = number_format($txmax,1);
$txmaxtime = date("g:ia", $txmaxstamp);
$txmin = number_format($txmin,1);
$txmintime = date("g:ia", $txminstamp);
if($cnt > 0)
$txmean = round(($txsum/$cnt),1);
$txdaily = round($txmean*60*60*24/$kbsize);
if ($txdaily >= $kbsize) {
$txdaily = round($txdaily/$kbsize,1);
$txdaily_units = "GB";
}
else {
$txdaily_units = "MB";
}
$rxmax = number_format($rxmax,1);
$rxmaxtime = date("g:ia", $rxmaxstamp);
$rxmin = number_format($rxmin,1);
$rxmintime = date("g:ia", $rxminstamp);
if($cnt > 0)
$rxmean = round(($rxsum/$cnt),1);
$rxdaily = round($rxmean*60*60*24/$kbsize);
if ($rxdaily >= $kbsize) {
$rxdaily = round($rxdaily/$kbsize,1);
$rxdaily_units = "GB";
}
else {
$rxdaily_units = "MB";
}
// list for dropdown log selector.
chdir($datadir);
$dirlist = `/bin/ls *.log`;
$parts = explode("\n",$dirlist);
foreach ($parts as $log) {
$log = trim($log);
if ($log && $log !== 'today.log') {
$file_parts = explode(".",$log);
$logdate = date("d M Y", $file_parts[0]);
$curr_log = explode(".",$logfile);
$curr_log = $curr_log[0];
// ------------------------------------------------------
// fix for date bug need to find out exactly why this happens
if ($curr_log == '') {
$curr_log->setDate(null);
}
// ------------------------------------------------------
if ($logdate == date("d M Y", (int)$curr_log ) )
{
$sel[] = "\n";
}
else
{
$sel[] = "\n";
}
}
}
if (isset($sel)) {
$sel = array_reverse($sel);
$newsel = join($sel);
}
if ($logfile == 'today.log') {
$refresh = "\n";
}
else {
if ($_GET['load'] == 1) { $get = "?load=1"; }
elseif ($_GET['load'] == 5) { $get = "?load=5"; }
elseif ($_GET['load'] == 15) { $get = "?load=15"; }
$todaybutton = " ";
}
if (isset($newsel)) {
if ($_GET['load']) { $hidin = ""; }
$form = "";
}
elseif ($logfile !== 'today.log') {
$form = "$todaybutton
";
}
else {
$form = " ";
}
} // close if(!$m)
else {
list($oomgcols,$oomgtime) = drawblank($oomgcols,$oomgtime,$hour,$logfile);
list($privcols,$privtime) = drawblank($privcols,$privtime,$hour,$logfile);
$oomgmax = number_format(round(($oomgmax/256),1),1);
$oomgmin = number_format(round(($oomgmin/256),1),1);
$oomgmid = number_format(round(($oomgmid/256),1),1);
$oomgmean = ($oomgsum/$cnt);
$oomgmean = number_format(round(($oomgmean/256),1),1);
$oomglast = number_format(round(($oomglast/256),1),1);
$oomgmaxtime = date("g:ia", $oomgmaxstamp);
$oomgmintime = date("g:ia", $oomgminstamp);
$privmax = number_format(round(($privmax/256),1),1);
$privmin = number_format(round(($privmin/256),1),1);
$privmid = number_format(round(($privmid/256),1),1);
$privmean = ($privsum/$cnt);
$privmean = number_format(round(($privmean/256),1),1);
$privlast = number_format(round(($privlast/256),1),1);
$privmaxtime = date("g:ia", $privmaxstamp);
$privmintime = date("g:ia", $privminstamp);
}
// Construct links.
if ($vps && $logfile && $logfile !== 'today.log') {
$memlink = "privvmpages
\n";
}
elseif ($vps) {
$memlink = "privvmpages
\n";
}
else {
$memlink = "memory usage
";
}
if ($logfile !== 'today.log') {
if ($ld==0) { $ldlink1 = "1-min"; }
else { $ldlink1 = "1-min"; }
if ($ld==1) { $ldlink5 = "5-min"; }
else { $ldlink5 = "5-min"; }
if ($ld==2) { $ldlink15 = "15-min"; }
else { $ldlink15 = "15-min"; }
}
else {
if ($ld==0) { $ldlink1 = "1-min"; }
else { $ldlink1 = "1-min"; }
if ($ld==1) { $ldlink5 = "5-min"; }
else { $ldlink5 = "5-min"; }
if ($ld==2) { $ldlink15 = "15-min"; }
else { $ldlink15 = "15-min"; }
}
// Time/date of last update (if not a logfile).
if (!isset($timedate)) {
$tz = date('T',time());
$now = date('l, M. j',$last);
$miltime = date('Hi',$last);
$aptime = date('g:i a',$last);
$timedate = "Today - $now - last update at $miltime ($aptime) $tz";
}
// Get the end time for page gen time.
$mtime = explode (" ", microtime());
$tend = $mtime[0] + $mtime[1];
$totaltime = round(($tend - $tstart),4);
$pagegen = "HTML graphs generated in $totaltime sec.";
// Functions ==========================================================--------
function drawblankinitially($cols, $times, $last_hour, $hour)
{
for ($c = $last_hour;$c<$hour;$c++)
{
$cols.= "\n";
if ($c%2==0)
$times.= "\n | ".$t." | ";
}
return array($cols,$times);
}
// Complete a table to the full 24 hours.
function drawblank($cols, $times, $lasthour, $logfile) {
$cols .= "\n\n";
$addhours = 23-$lasthour;
$disphour = $lasthour+1;
while ($addhours > 0) {
$cols .= "\n | \n";
if (is_int($disphour/2)) {
$times .= "\n$disphour | ";
}
$disphour++;
$addhours = $addhours-1;
}
if ($logfile == 'today.log') { $lastclass = 'timelastdim'; }
else { $lastclass = 'timelast'; }
$times .= "\n$disphour | ";
return array($cols,$times);
}
// Draw a chart for memory usage.
function chartmem($memcols,$memtime,$mem,$memmax,$memmin,$memmid,$memrange,$oomgbarrier,$privbarrier,$hour,$minute,$timestamp,$last,$gap) {
$memdiff = $mem - $memmin;
$memheight = $memrange ? ceil($memdiff/$memrange*100) : $memdiff;
$memclass = 'gr';
// Hack for IE...
if ($memheight == 1) { $memheight = 2; }
if ($memheight == 0) { $memheight = 2; $memclass = 'wh'; }
// --
$memtop = 100-$memheight;
if (!$memcols) {
if ($hour > 0)
{
for ($c = 0;$c<$hour;$c++)
{
$memcols.= "\n";
$t = "";
if ($c%2==0) $t = $c;
$memtime.= "\n | ".$t." | ";
}
}
if ($minute < 2)
{
$memcols .= "\n\n";
if (is_int($hour/2))
{
if ($hour == 0)
$memtime .= "\n | $hour | ";
else
$memtime .= "\n$hour | ";
}
}
else
{
if (is_int($hour/2))
$memtime .= "\n$hour | ";
$memcols .= "\n\n";
for ($c = 0; $c < $minute;$c=$c+6)
$memcols .= "\n";
$memcols .= "\n";
}
}
elseif ($memcols && ($minute < 2 || $gap)) {
if (!$gap)
$memcols .= "\n | \n\n";
if (is_int($hour/2)) {
$memtime .= "\n | $hour | ";
}
}
else {
$memcols .= "\n";
}
return array($memcols,$memtime);
}
?>