From 571c9d5b0e27ee321b58207f29338743577e5d22 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Sun, 29 Apr 2012 20:04:35 +0000 Subject: [PATCH] optimize sql for versioncheck stats git-svn-id: http://www.observium.org/svn/observer/trunk@3098 61d68cd4-352d-0410-923a-c4978735b2b8 --- discovery.php | 15 +++---- includes/versioncheck.inc.php | 75 ++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/discovery.php b/discovery.php index 3ef62738b9..18118e0c1a 100755 --- a/discovery.php +++ b/discovery.php @@ -116,14 +116,15 @@ if($options['h'] != "new" && $config['version_check']) { 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"); } diff --git a/includes/versioncheck.inc.php b/includes/versioncheck.inc.php index 7225e39347..9f4695f6a3 100644 --- a/includes/versioncheck.inc.php +++ b/includes/versioncheck.inc.php @@ -9,53 +9,54 @@ $stats['services'] = dbFetchCell("SELECT count(*) FROM services"); $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); } ?>