2007-09-11 12:39:31 +00:00
|
|
|
<?php
|
|
|
|
|
2007-09-12 13:12:41 +00:00
|
|
|
function draw_graph($xarr, $arr) {
|
|
|
|
require_once ("jpgraph/jpgraph.php");
|
|
|
|
require_once ("jpgraph/jpgraph_line.php");
|
|
|
|
require_once ("jpgraph/jpgraph_bar.php");
|
|
|
|
require_once ("jpgraph/jpgraph_log.php");
|
|
|
|
|
2007-09-11 12:39:31 +00:00
|
|
|
|
|
|
|
// Create the graph. These two calls are always required
|
|
|
|
$graph = new Graph(350,250,"auto");
|
|
|
|
//$graph->SetScale("lin");
|
|
|
|
//$graph->SetScale("textlin");
|
|
|
|
$graph->SetScale("loglin");
|
|
|
|
|
|
|
|
// Create the linear plot
|
|
|
|
$lineplot=new BarPlot($arr, $xarr);
|
|
|
|
$lineplot->SetColor("blue");
|
|
|
|
|
|
|
|
// Add the plot to the graph
|
|
|
|
$graph->Add($lineplot);
|
|
|
|
|
|
|
|
// Display the graph
|
|
|
|
$graph->Stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_text($xarr, $yarr) {
|
|
|
|
$n = sizeof($xarr);
|
|
|
|
for ($i=0; $i<$n; $i++) {
|
|
|
|
echo "<br>$xarr[$i] $yarr[$i]\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_graph() {
|
|
|
|
require_once("../inc/db.inc");
|
|
|
|
db_init();
|
|
|
|
|
|
|
|
$xaxis = $_GET['xaxis'];
|
|
|
|
$yaxis = $_GET['yaxis'];
|
|
|
|
$granularity = $_GET['granularity'];
|
2007-09-12 13:12:41 +00:00
|
|
|
$active = $_GET['active'];
|
|
|
|
$inactive = $_GET['inactive'];
|
|
|
|
$show_text = $_GET['show_text'];
|
|
|
|
|
|
|
|
if (!$active && !$inactive) {
|
|
|
|
echo "You must select at least one of (active, inactive)";
|
|
|
|
exit();
|
|
|
|
}
|
2007-09-11 12:39:31 +00:00
|
|
|
|
2007-09-12 13:12:41 +00:00
|
|
|
$fields = 'host.id, user.create_time';
|
|
|
|
if ($xaxis == 'active' || !$active || !$inactive) {
|
2007-09-11 12:39:31 +00:00
|
|
|
$query = "select $fields, max(rpc_time) as max_rpc_time from host, user where host.userid=user.id group by userid";
|
|
|
|
} else {
|
|
|
|
$query = 'select $fields from user';
|
|
|
|
}
|
|
|
|
$result = mysql_query($query);
|
|
|
|
$yarr = array();
|
|
|
|
$now = time();
|
|
|
|
$maxind = 0;
|
2007-09-12 13:12:41 +00:00
|
|
|
$active_thresh = time() - 30*86400;
|
2007-09-11 12:39:31 +00:00
|
|
|
while ($user = mysql_fetch_object($result)) {
|
|
|
|
$val = $now - $user->max_rpc_time;
|
2007-09-12 13:12:41 +00:00
|
|
|
if (!$active) {
|
|
|
|
if ($user->max_rpc_time > $active_thresh) continue;
|
|
|
|
}
|
|
|
|
if (!$inactive) {
|
|
|
|
if ($user->max_rpc_time < $active_thresh) continue;
|
|
|
|
}
|
|
|
|
$life = $user->max_rpc_time - $user->create_time;
|
|
|
|
$ind = $life/$granularity;
|
2007-09-11 12:39:31 +00:00
|
|
|
$ind = (int)$ind;
|
|
|
|
$yarr[$ind]++;
|
|
|
|
if ($ind > $maxind) $maxind = $ind;
|
|
|
|
}
|
|
|
|
$xarr = array();
|
|
|
|
for ($i=0; $i<=$maxind; $i++) {
|
|
|
|
$xarr[$i] = $i;
|
|
|
|
if (is_null($yarr[$i])) $yarr[$i]=0;
|
|
|
|
}
|
2007-09-12 13:12:41 +00:00
|
|
|
if ($show_text) {
|
|
|
|
show_text($xarr, $yarr);
|
|
|
|
} else {
|
|
|
|
draw_graph($xarr, $yarr);
|
|
|
|
}
|
2007-09-11 12:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function show_form() {
|
|
|
|
echo "
|
|
|
|
<form action=user_graph.php>
|
|
|
|
X axis:
|
|
|
|
<select name=xaxis>
|
|
|
|
<option value=active>Active time
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Y axis:
|
|
|
|
<select name=yaxis>
|
|
|
|
<option value='count'>Count
|
|
|
|
<option value='rac'>RAC
|
|
|
|
<option value='tc'>Total credit
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<p>
|
2007-09-12 13:12:41 +00:00
|
|
|
Show active users?
|
2007-09-11 12:39:31 +00:00
|
|
|
<input type=checkbox name=active>
|
|
|
|
|
2007-09-12 13:12:41 +00:00
|
|
|
<p>
|
|
|
|
Show inactive users?
|
|
|
|
<input type=checkbox name=inactive>
|
|
|
|
|
2007-09-11 12:39:31 +00:00
|
|
|
<p>
|
|
|
|
Granularity:
|
|
|
|
<input name=granularity value=86400>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Show as text?
|
|
|
|
<input type=checkbox name=show_text>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<input type=submit name=submit value=OK>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_GET['submit']) {
|
|
|
|
show_graph();
|
|
|
|
} else {
|
|
|
|
show_form();
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|