Skip to content

Commit

Permalink
optimize sql for versioncheck stats
Browse files Browse the repository at this point in the history
git-svn-id: http://www.observium.org/svn/observer/trunk@3098 61d68cd4-352d-0410-923a-c4978735b2b8
  • Loading branch information
Tom Laermans committed Apr 29, 2012
1 parent 2e2d60f commit 571c9d5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
15 changes: 8 additions & 7 deletions discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@
include("includes/versioncheck.inc.php");
}

if(!isset($options['q'])) {
if (!isset($options['q']))
{
echo('MySQL: Cell['.($db_stats['fetchcell']+0).'/'.round($db_stats['fetchcell_sec']+0,2).'s]'.
' Row['.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,2).'s]'.
' Rows['.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,2).'s]'.
' Column['.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,2).'s]'.
' Update['.($db_stats['update']+0).'/'.round($db_stats['update_sec']+0,2).'s]'.
' Insert['.($db_stats['insert']+0). '/'.round($db_stats['insert_sec']+0,2).'s]'.
' Delete['.($db_stats['delete']+0). '/'.round($db_stats['delete_sec']+0,2).'s]');
' Row['.($db_stats['fetchrow']+0). '/'.round($db_stats['fetchrow_sec']+0,2).'s]'.
' Rows['.($db_stats['fetchrows']+0).'/'.round($db_stats['fetchrows_sec']+0,2).'s]'.
' Column['.($db_stats['fetchcol']+0). '/'.round($db_stats['fetchcol_sec']+0,2).'s]'.
' Update['.($db_stats['update']+0).'/'.round($db_stats['update_sec']+0,2).'s]'.
' Insert['.($db_stats['insert']+0). '/'.round($db_stats['insert_sec']+0,2).'s]'.
' Delete['.($db_stats['delete']+0). '/'.round($db_stats['delete_sec']+0,2).'s]');
echo("\n");
}

Expand Down
77 changes: 39 additions & 38 deletions includes/versioncheck.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,54 @@
$stats['applications'] = dbFetchCell("SELECT count(*) FROM applications");
$stats['bgp'] = dbFetchCell("SELECT count(*) FROM bgpPeers");

foreach (dbFetch("SELECT `os` FROM `devices` GROUP BY `os`") as $dt_data)
foreach (dbFetch("SELECT COUNT(*) AS count,os from devices group by `os`") as $dt_data)
{
$stats['devicetypes'][$dt_data[os]] = dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `os` = '".$dt_data['os']."'");
$stats['devicetypes2'][$dt_data['os']] = $dt_data['count'];
}

$stats = serialize($stats[$dt_data[os]]);
$stats = serialize($stats[$dt_data['os']]);

$dataHandle = fopen("http://www.observium.org/latest.php?i=".$stats['ports']."&d=".$stats['devices']."&stats=".$stats."&v=".$config['version'], r);

if($dataHandle)
if ($dataHandle)
{
while (!feof($dataHandle))
while (!feof($dataHandle))
{
$data.= fread($dataHandle, 4096);
}
if ($data)
{
list($omnipotence, $year, $month, $revision) = explode(".", $data);
list($cur, $tag) = explode("-", $config['version']);
list($cur_omnipotence, $cur_year, $cur_month, $cur_revision) = explode(".", $cur);

if ($argv[1] == "--cron" || isset($options['q']))
{
$fd = fopen($config['log_file'],'a');
fputs($fd,$string . "\n");
fclose($fd);

shell_exec("echo $omnipotence.$year.$month.$month > ".$config['rrd_dir']."/version.txt ");
} else {
if ($cur != $data)
{
echo("Current Version : $cur_omnipotence.$cur_year.$cur_month.$cur_revision \n");

if ($omnipotence > $cur_omnipotence)
{
$data.= fread($dataHandle, 4096);
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($year > $cur_year) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($month > $cur_month) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($revision > $cur_revision) {
echo("New release : $omnipotence.$year.$month.$revision\n");
}
if ($data)
{
list($omnipotence, $year, $month, $revision) = explode(".", $data);
list($cur, $tag) = explode("-", $config['version']);
list($cur_omnipotence, $cur_year, $cur_month, $cur_revision) = explode(".", $cur);

if ($argv[1] == "--cron" || isset($options['q'])) {

$fd = fopen($config['log_file'],'a');
fputs($fd,$string . "\n");
fclose($fd);

shell_exec("echo $omnipotence.$year.$month.$month > ".$config['rrd_dir']."/version.txt ");

} else {

if ($cur != $data) {
echo("Current Version : $cur_omnipotence.$cur_year.$cur_month.$cur_revision \n");

if ($omnipotence > $cur_omnipotence) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($year > $cur_year) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($month > $cur_month) {
echo("New version : $omnipotence.$year.$month.$revision\n");
} elseif ($revision > $cur_revision) {
echo("New release : $omnipotence.$year.$month.$revision\n");
}
}
}
}
fclose($dataHandle);
}
}
}

fclose($dataHandle);
}

?>

0 comments on commit 571c9d5

Please sign in to comment.