From 5ce2f693d6e75d1e3fed9995a2e3ddb32b689d39 Mon Sep 17 00:00:00 2001 From: Frank Fegert Date: Sat, 23 May 2009 16:50:14 +0000 Subject: [PATCH] - Added SQL file for new DB entries (only temporarily until first release). - Added runtime profiling output to PollD. - Fixed minor bug in PollD for query runtime > 900 sec situations. - Added log to file functionality to PollD. --- includes/polld.php | 34 +++++++++++++++++++++++++++++----- polld/tmonpolld.php | 2 +- scripts/tsmmonitor_diff.sql | 13 +++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 scripts/tsmmonitor_diff.sql diff --git a/includes/polld.php b/includes/polld.php index 3931751..83239eb 100644 --- a/includes/polld.php +++ b/includes/polld.php @@ -47,6 +47,7 @@ class PollD { var $overviewqueries; var $adodb; var $debuglevel; // VERBOSE=4, INFO=3, WARN=2, ERROR=1, OFF=0 + var $loghandle; var $log_timeneeded; var $log_unchangedresult; @@ -65,6 +66,15 @@ class PollD { $this->setDebuglevel("INFO"); $this->adodb = $adodb; + $sql = "select confval from cfg_config WHERE `confkey`='loglevel_polld'"; + $loglevel = $this->adodb->fetchArrayDB($sql); + $loglevel = strtoupper($loglevel[0][confval]); + $this->setDebuglevel("$loglevel"); + $sql = "select confval from cfg_config WHERE `confkey`='path_polldlog'"; + $logfile = $this->adodb->fetchArrayDB($sql); + if ($logfile[0][confval] != "") { + $this->loghandle = fopen($logfile[0][confval], 'at'); + } $this->servers = $this->getServers(); $this->queries = $this->getQueries(); $this->overviewqueries = $this->getOverviewQueries(); @@ -101,7 +111,12 @@ class PollD { } if ($this->debuglevel >= $ilevel) { - echo $level.": ".$msg; + if ($this->loghandle) { + fwrite($this->loghandle, $level.": ".$msg); + } + else { + echo $level.": ".$msg; + } } } @@ -347,6 +362,8 @@ class PollD { * @param string $timestamp */ function pollQuery($query = "", $server = "", $ignorePollFreq = TRUE, $timestamp){ + $starttquery = time(); + $querytime = 0; $queryname = $query["name"]; $tablename = "res_".$queryname."_".$server["servername"]; @@ -391,10 +408,12 @@ class PollD { $this->writeMSG("Error while inserting into table (".$insertquery.")", "ERROR"); } } - $this->writeMSG("inserted new rows into ".$tablename."\n", "INFO"); + $querytime = time() - $starttquery; + $this->writeMSG("inserted new rows into ".$tablename." ($querytime sec)\n", "INFO"); $this->log_updated++; } else { - $this->writeMSG("no need to update result -> result is the same as last time\n", "INFO"); + $querytime = time() - $starttquery; + $this->writeMSG("no need to update result -> result is the same as last time ($querytime sec)\n", "INFO"); $this->log_unchangedresult++; } } else { @@ -416,6 +435,8 @@ class PollD { * @param string $timestamp */ function pollOverviewQuery($query = "", $server = "", $timestamp){ + $starttquery = time(); + $querytime = 0; $tablename = "res_overview_".$server["servername"]; $this->writeMSG("---------".$query["name"].": ", "INFO"); @@ -426,7 +447,8 @@ class PollD { if ($result != "") { foreach ($result["sql"] as $insertquery) { $this->adodb->execDB($insertquery); - $this->writeMSG("inserted row\n", "INFO"); + $querytime = time() - $starttquery; + $this->writeMSG("inserted row ($querytime sec)\n", "INFO"); } } else { $this->writeMSG("There was a problem querying the TSM Server ".$server["servername"]."!\n", "ERROR"); @@ -602,12 +624,14 @@ class PollD { $this->writeMSG("needed ".(time()-$timestamp)." seconds for this run.\n", "INFO"); //$tempsleeptime = $sleeptime-(time()-$timestamp); $tempsleeptime = 900 -(time()-$timestamp); + if ($tempsleeptime < 0) { + $tempsleeptime = 0; + } $this->writeMSG("sleeping for ".$tempsleeptime." seconds...\n", "WARN"); $this->writeMSG("next run will be at ".strftime("%H:%M:%S", (time()+$tempsleeptime))."\n\n", "WARN"); $this->setPollDStatus("sleeping", $timestamp, (time()+$tempsleeptime)); - sleep ($tempsleeptime); } else { diff --git a/polld/tmonpolld.php b/polld/tmonpolld.php index ee666f6..badacfb 100644 --- a/polld/tmonpolld.php +++ b/polld/tmonpolld.php @@ -37,7 +37,7 @@ include_once("../includes/global.php"); $tmonpolld = new PollD($adodb); -$tmonpolld->setDebuglevel("WARN"); +//$tmonpolld->setDebuglevel("WARN"); $tmonpolld->controlPollD("on"); $tmonpolld->poll(); diff --git a/scripts/tsmmonitor_diff.sql b/scripts/tsmmonitor_diff.sql new file mode 100644 index 0000000..bcd935d --- /dev/null +++ b/scripts/tsmmonitor_diff.sql @@ -0,0 +1,13 @@ +use tsmmonitor; +# Make name consistent with other _24h queries +UPDATE cfg_queries SET name='archives_24h' WHERE name='archives_24'; +# Allow longer confvals e.g. file paths +ALTER TABLE cfg_config MODIFY confval varchar(255) collate utf8_unicode_ci NOT NULL; +# Add description +UPDATE cfg_config SET description='TSM Monitor version' WHERE confkey='version'; +# Add new configuration entries +INSERT INTO cfg_config (confkey,confval,description) VALUES ('path_tmlog','','TSM Monitor Logfile Path'); +INSERT INTO cfg_config (confkey,confval,description) VALUES ('path_polldlog','','PollD Logfile Path'); +INSERT INTO cfg_config (confkey,confval,description) VALUES ('loglevel_tm','INFO','TSM Monitor Log Level'); +INSERT INTO cfg_config (confkey,confval,description) VALUES ('loglevel_polld','INFO','PollD Log Level'); +