<?php
/*
count logins
count logouts
subtract, that will be the number of users currently online.
*/
//takes a file in the form of a string
//returns an array of arrays in the form of array(timestamp, username, in/out)
function parseLogFile($file)
{
$logindata = file($file);
$matches = array();
$pattern = '/^\[([\d]{2,2})-([\d]{2,2}) ([\d]{2,2}):([\d]{2,2}):([\d]{2,2})\] Authenticating ([\d\s\w]{3,})$/'; // TODO: Chant this over the corpses of a thousand men to summon Yog'Suggoth
foreach($logindata as $login)
{
if(strstr($login, 'Authenticating'))
{
preg_match_all($pattern, $login, $matches);
$hour = $matches[3][0];
$minute = $matches[4][0];
$second = $matches[5][0];
$month = $matches[1][0];
$day = $matches[2][0];
$year = date('Y');
$logins[] = array('timestamp' => mktime($hour, $minute, $second, $month, $day, $year), 'username' => trim($matches[6][0]), 'movement' => 'in');
}
}
return $logins;
}
/*
function getLoginCounts($logindata)
{
//Currently does nothing but sit here and wait for a patch to opensim to tell us when a user has definitively logged off.
$in = 0;
$out = 0;
foreach($logindata as $login)
{
if($login['movement'] == 'in')
{
$in += 1;
}
elseif($login['movement'] == 'out')
{
$out += 1;
}
}
return array('in' => $in, 'out' => $out);
}
*/
function returnDataWithinDateRange($upperbound, $lowerbound, $array)
{
$returnvalue = array();
foreach($array as $row)
{
if($row['timestamp'] <= $upperbound)
{
if($row['timestamp'] >= $lowerbound)
{
$returnvalue[] = $row;
}
}
}
return $returnvalue;
}
$file = 'opengrid-userserver-console.log';
$logindata = parseLogFile($file);
/*$logincounts = getLoginCounts($logindata);
echo $logincounts['in']-$logincounts['out'];
echo "\r\n";*/
/*
Notes, a la ckrinke:
Minimum, we need to count a daily count. Ideally, it would be nice to see each day and add to it. It would be nice to see trends during the week and the month.
Some sort of bar chart would be wonderful, both hourly (for the last day or so) and daily.
Perhaps we should start small, but have say, one bar chart in .svg or .png format. I think .svg is just fine and see where we go.
I am sorta thinking like a moving graph ala stock prices, or perhaps a simpler model where we start over each month.
Those things that all three roles would be interested in should be the higher priority, methinks.
So, ...., a) are the logins trending up or down b) is there a part of the day with heavier logins then others c) is there a part of the week with heavier logins then others. d) are we growing linearly or exponentially.
*/
echo '<pre>';
echo 'Total number of logins to date: '.count($logindata)."\r\n"; // daily count
//FIXME: There's a bug here. It makes all our data show up in the past as well as the present.
$oldvalue = 1;
for($hour = 0; $hour <= 168; $hour++)
{
$value = count(returnDataWithinDateRange(time()-($oldvalue*3600), strtotime('-'.$hour.' hour'), $logindata));
echo 'Total number of logins between '.$oldvalue.' hours ago and '.$hour.' hours ago: '.$value."\r\n";
$oldvalue = $hour;
}
/*
foreach($logindata as $login)
{
$csv .= $login['timestamp'].',';
$csv .= $login['username'];
$csv .= "\r\n";
}
echo($csv);
*/
?>