jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [poller-common.php] - Diff between revs 1 and 13

Show entire file Ignore whitespace

Rev 1 Rev 13
Line 1... Line 1...
<? <?php
// common code used by the poller, the manual-run from the Cacti UI, and from the command-line manual-run. // common code used by the poller, the manual-run from the Cacti UI, and from the command-line manual-run.
// this is the easiest way to keep it all consistent! // this is the easiest way to keep it all consistent!
   
  function weathermap_memory_check($note="MEM")
  {
  if(function_exists("memory_get_usage"))
  {
  $mem_used = nice_bandwidth(memory_get_usage());
  $mem_allowed = ini_get("memory_limit");
  debug("$note: memory_get_usage() says ".$mem_used."Bytes used. Limit is ".$mem_allowed."\n");
  }
  }
   
function weathermap_run_maps($mydir) { function weathermap_run_maps($mydir) {
global $config; global $config;
global $weathermap_debugging, $WEATHERMAP_VERSION; global $weathermap_debugging, $WEATHERMAP_VERSION;
   
Line 28... Line 38...
// moved this outside the module_checks, so there should always be something in the logs! // moved this outside the module_checks, so there should always be something in the logs!
if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION starting - $mode_message",true,"WEATHERMAP"); if($quietlogging==0) cacti_log("Weathermap $WEATHERMAP_VERSION starting - $mode_message",true,"WEATHERMAP");
   
if(module_checks()) if(module_checks())
{ {
  weathermap_memory_check("MEM Initial");
// move to the weathermap folder so all those relatives paths don't *have* to be absolute // move to the weathermap folder so all those relatives paths don't *have* to be absolute
$orig_cwd = getcwd(); $orig_cwd = getcwd();
chdir($mydir); chdir($mydir);
   
// first, see if the output directory even exists // first, see if the output directory even exists
Line 62... Line 72...
$thumbimagefile = $outdir.DIRECTORY_SEPARATOR."weathermap_thumb_".$map['id'].".".$imageformat; $thumbimagefile = $outdir.DIRECTORY_SEPARATOR."weathermap_thumb_".$map['id'].".".$imageformat;
   
if(file_exists($mapfile)) if(file_exists($mapfile))
{ {
if($quietlogging==0) warn("Map: $mapfile -> $htmlfile & $imagefile"); if($quietlogging==0) warn("Map: $mapfile -> $htmlfile & $imagefile");
  weathermap_memory_check("MEM starting $mapcount");
$wmap = new Weathermap; $wmap = new Weathermap;
$wmap->context = "cacti"; $wmap->context = "cacti";
   
// we can grab the rrdtool path from Cacti's config, in this case // we can grab the rrdtool path from Cacti's config, in this case
$wmap->rrdtool = read_config_option("path_rrdtool"); $wmap->rrdtool = read_config_option("path_rrdtool");
   
$wmap->ReadConfig($mapfile); $wmap->ReadConfig($mapfile);
  weathermap_memory_check("MEM postread $mapcount");
$wmap->ReadData(); $wmap->ReadData();
  weathermap_memory_check("MEM postdata $mapcount");
   
// $wmap->imageuri = $config['url_path'].'/plugins/weathermap/output/weathermap_'.$map['id'].".".$imageformat; // $wmap->imageuri = $config['url_path'].'/plugins/weathermap/output/weathermap_'.$map['id'].".".$imageformat;
$wmap->imageuri = 'output/weathermap_'.$map['id'].".".$imageformat; $wmap->imageuri = 'output/weathermap_'.$map['id'].".".$imageformat;
   
if($quietlogging==0) warn("About to write image file. If this is the last message in your log, increase memory_limit in php.ini"); if($quietlogging==0) warn("About to write image file. If this is the last message in your log, increase memory_limit in php.ini");
if(function_exists("memory_get_usage")) weathermap_memory_check("MEM pre-render $mapcount");
{  
$mem_used = nice_bandwidth(memory_get_usage());  
$mem_allowed = ini_get("memory_limit");  
debug("memory_get_usage() says ".$mem_used."Bytes used. Limit is ".$mem_allowed."\n");  
}  
   
   
$wmap->DrawMap($imagefile,$thumbimagefile,read_config_option("weathermap_thumbsize")); $wmap->DrawMap($imagefile,$thumbimagefile,read_config_option("weathermap_thumbsize"));
   
if($quietlogging==0) warn("Wrote map to $imagefile and $thumbimagefile"); if($quietlogging==0) warn("Wrote map to $imagefile and $thumbimagefile");
$fd = @fopen($htmlfile, 'w'); $fd = @fopen($htmlfile, 'w');
if($fd != FALSE) if($fd != FALSE)
{ {
fwrite($fd, $wmap->MakeHTML('weathermap_'.$map['id'].'_imap')); fwrite($fd, $wmap->MakeHTML('weathermap_'.$map['id'].'_imap'));
Line 107... Line 113...
warn("Failed to create $htmlfile - permissions of output directory are wrong?\n"); warn("Failed to create $htmlfile - permissions of output directory are wrong?\n");
} }
} }
   
db_execute("update weathermap_maps set titlecache='".mysql_real_escape_string($wmap->title)."' where id=".$map['id']); db_execute("update weathermap_maps set titlecache='".mysql_real_escape_string($wmap->title)."' where id=".$map['id']);
   
  unset($wmap);
  weathermap_memory_check("MEM after $mapcount");
$mapcount++; $mapcount++;
} }
else else
{ {
warn("Mapfile $mapfile is not readable or doesn't exist"); warn("Mapfile $mapfile is not readable or doesn't exist");
Line 130... Line 139...
} }
else else
{ {
warn("Output directory ($outdir) doesn't exist!. No maps created. You probably need to create that directory, and make it writable by the poller process (like you did with the RRA directory)"); warn("Output directory ($outdir) doesn't exist!. No maps created. You probably need to create that directory, and make it writable by the poller process (like you did with the RRA directory)");
} }
  weathermap_memory_check("MEM Final");
chdir($orig_cwd); chdir($orig_cwd);
if($quietlogging==0) warn("Weathermap $WEATHERMAP_VERSION run complete - $mapcount maps were run"); if($quietlogging==0) warn("Weathermap $WEATHERMAP_VERSION run complete - $mapcount maps were run");
} }
else else
{ {

Powered by WebSVN 2.2.1