RRD maxvalue different than MySQL maxvalue?

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
wesphillips
Posts: 21
Joined: Tue May 28, 2002 8:59 am

RRD maxvalue different than MySQL maxvalue?

Post by wesphillips »

This has happened to me in the past. It happens because the file permissions get set incorrectly when the RRD is created. Your cactiuser has to be able to access it, but the apache user ALSO has to be able to write to the file as well to update any changes you make through cacti. So when you change the maxvalue in cacti and check the "Update Changes in .rrd File " checkbox, the change dows not take place. This can cause clipping if the bandwidth is increased after RRD creation. This script will check the RRD and the MySQL database and update the RRD file to match the database.

This script is a Perl script and requires Mysql and RRDs modules. the RRDs module comes with RRDTool, and the MySQL module is in the DBD::MySQL module on CPAN.

this script should go into your cacti directory. Give this file restrictive permissions, like 600 or 660, since it will be residing inside the webroot.

Edit the variables at the beginning of the file to match the settings of your server.

Code: Select all

maxset.pl
#!/usr/bin/perl

use Mysql;
use RRDs;

###
### Edit these values
###

my $rrdpath = "/var/www/html/cacti/rra/";
my $rrdtool = "/usr/local/rrdtool-1.0.38/bin/rrdtool"; 

###
### The code below this line should not have to be edited
###

if (-e './include/config.php') { 
  open (CFGFILE, './include/config.php') or die "Couldn't open the config.php file\n";    
    for $config (<CFGFILE>) { 
      chomp $config; 
      if ($config =~ /^\$database_default/) { 
        $dbase = (split /\"/, $config)[1]; 
        $p++; 
        next; 
      } elsif ($config =~ /^\$database_hostname/) { 
        $sqlhost = (split /\"/, $config)[1]; 
        $p++; 
        next; 
      } elsif ($config =~ /^\$database_username/) { 
        $user = (split /\"/, $config)[1]; 
        $p++; 
        next; 
      } elsif ($config =~ /^\$database_password/) { 
        $pass = (split /\"/, $config)[1]; 
        $p++; 
        next; 
      } 
  } 
} else { 
  die "could not find config.php"; 
} 

$db = Mysql->connect($sqlhost, $dbase, $user, $pass) or die ("Cannot connect to MySQL server on $sqlhost");
$query = $db->query("SELECT DSPath,MaxValue,DSName FROM rrd_ds");
while (my($dbdspath,$dbmaxvalue, $dbdsname) = $query->fetchrow_array()) {
  @fstrrd = split("/", $dbdspath);
  $fstrrd[1] =~ s/\.rrd//;
  $rrd = $fstrrd[1];
  $file = $rrdpath . $rrd . "\.rrd";
  if ( ! -e $file) { die ("File $file does not exist"); }
  $rrdoutput = `$rrdtool info $rrdpath$rrd\.rrd | grep "].max"`;
  chomp($rrdoutput);
  @dsplit = split(" = ", $rrdoutput);
  $rrdmaxvalue = $dsplit[1];
  @subs = split("e", $rrdmaxvalue);
  $subs[1] = (substr($subs[1], 1)) * 1;
  $rrdvalue = $subs[0] * (10 ** $subs[1]);
  if ( $dbmaxvalue ne $rrdvalue ) {
    RRDs::tune($file, "-a", $dbdsname . ":" . $dbmaxvalue);
    my $err=RRDs::error;
    print "$file changed from $rrdvalue to $dbmaxvalue\n";
    if ($err) {
      warn "ERROR updating $file: $err\n"
      };
  }
}
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests