Commit 189b13a4 authored by ueli heuer's avatar ueli heuer 👾
Browse files

dvg_tunerrd: observes now individual max values

parent 8069b76d
......@@ -31,7 +31,7 @@ There could be some more bugs. If you find one (or more) please report it to I<h
=head1 COPYRIGHT
This program is Copyright (C) 2005 ... 2009 by Ueli Heuer <ueli@dvgtool.org>.
This program is Copyright (c) ... 2020 by Ueli Heuer <ueli@dvgtool.org>.
It is licensed under the terms of the GPL.
......@@ -44,26 +44,30 @@ use lib "$FindBin::RealBin/../lib";
use DVG_config;
use DVG_tool;
use Data::Dumper;
use RRDs;
# {{{ cmdline
use Getopt::Long;
my ($result,$version,$revision,$help,$verbose);
$result = GetOptions (
my ($result,$version,$help,$verbose,$DEBUG);
$DEBUG=0;
$result = GetOptions(
'version|v' => \$version,
'help|h|?' => \$help,
'verbose|b' => \$verbose,
'debug|d' => \$DEBUG,
);
if ( $version) {
# print our version and revision and then go home
my ( $revision );
( $revision = '$Revision$' ) =~ s/^\$[R]evision:\s*([^ ]*)\s*\$$/$1/;
printf ("%s DVG-Version: %s File-Rev %s\n",$0,DVG_config::dvg_version(),$revision);
printf ("%s DVG-Version: %s\n",$0,DVG_config::dvg_version());
}
if ( $help ) {
exec ("perldoc $0");
}
if ( $version || $help ) {
exit;
}
......@@ -72,61 +76,84 @@ if ( $version || $help ) {
my $db = db_connect('dvgdb','RO'); # connect to the dvgdb database
DVG_tool::init($db);
my ($DEBUG);
$DEBUG = 0;
# {{{ sub tune_rrd {
sub tune_rrd {
my ($datafile_name, @value ) =@_;
my ($datafile_name, @max, @min ) =@_;
my (@args,$i,$error);
# create maximmums ...
@args = ($datafile_name);
for ($i = 0; $i <= $#value; $i++ ) {
push (@args,"--maximum","ds$i:$value[$i]");
for ($i = 0; $i <= $#max; $i++ ) {
push (@args,"--maximum","ds$i:$max[$i]");
}
if ($DEBUG > 2) {
$Data::Dumper::Indent = 1;
print Dumper(@args);
}
print "$datafile_name @value\n" if $DEBUG > 2;
RRDs::tune (@args);
RRDs::tune (@args);
$error = RRDs::error();
# create minimums ...
# @args = ($datafile_name);
# for ($i = 0; $i <= $#min; $i++ ) {
# push (@args,"--minimum","ds$i:$min[$i]");
# }
# if ($DEBUG > 2) {
# $Data::Dumper::Indent = 1;
# print Dumper(@args);
# }
# RRDs::tune (@args);
# $error = RRDs::error();
return $error;
}
#}}}
# {{{ main()
my ($activ_devices_sql,$activ_devices_h,$old_device_id,$params_sql,$params_h,$device_id,$max_param_id);
my (@max,$param_id,$param,$value,$datafile_name,$max,$absmax,$realmax);
$activ_devices_sql = "
SELECT dd.id, max_param
FROM
dvg_host dh,
dvg_device dd,
dvg_probe p, dvg_probe_args pa
WHERE dh.id = dd.host_id
AND dd.probe_id = p.id
AND pa.probe_id = p.id
AND dh.activ = 'y'
AND dd.activ = 'y'
my ($absmax, $activ_devices_h, $activ_devices_sql, $datafile_name,
$default_value, $device_id, $dsmax, $dsmin, $max, $max_param_id,
$min, $min_param_id, $old_device_id, $param, $param_id, $params_h,
$params_sql, $realmax, $value, @max, @min);
$activ_devices_sql =
"SELECT dd.id, pa.max_param
FROM dvg_host dh,
dvg_device dd,
dvg_probe p,
dvg_probe_args pa
WHERE dh.id = dd.host_id
AND dd.probe_id = p.id
AND pa.probe_id = p.id
AND dh.activ = 'y'
AND dd.activ = 'y'
ORDER BY dd.id, seq";
$activ_devices_h = $db->prepare($activ_devices_sql);
$activ_devices_h->execute;
if ($activ_devices_h->rows ) { # wenn es was zu tun gibt tun wir es
if ($activ_devices_h->rows ) {
$old_device_id = 0;
$params_sql = "SELECT pp.id, pp.param, ddp.value
FROM dvg_device_param ddp, dvg_probe_param pp
WHERE pp.id = ddp.oid_param_id
AND ddp.device_id = ?";
$params_sql =
'SELECT pp.id, pp.param, ddp.value
FROM dvg_device_param ddp,
dvg_probe_param pp
WHERE pp.id = ddp.oid_param_id
AND ddp.device_id = ?';
$params_h = $db->prepare($params_sql);
printf ("Need to work %d RRD-Files\n",$activ_devices_h->rows) if $verbose;
undef @max;
undef @min;
while (($device_id,$max_param_id) = $activ_devices_h->fetchrow) {
$params_h->execute($device_id);
$max=$absmax=0;
$params_h->execute($device_id,);
$max = $absmax = 0;
undef $dsmax;
while (($param_id,$param,$value)=$params_h->fetchrow ) {
if ( $param eq "#MAX#" || $max_param_id == $param_id ) {
if ($max_param_id > 0 && $max_param_id == $param_id ) {
$dsmax = $value;
} elsif ( $param eq "#MAX#" ) {
$max = $value;
} elsif ( $param eq "#ABSMAX#" ) {
$absmax = $value;
......@@ -136,14 +163,18 @@ if ($activ_devices_h->rows ) { # wenn es was zu tun gibt tun wir es
$datafile_name = DVG_tool::datafile_name($old_device_id);
if ( -f $datafile_name) {
printf ("Working on rrd file: %s\n",$datafile_name) if $verbose;
tune_rrd($datafile_name,@max);
tune_rrd($datafile_name,@max,@min);
} else {
printf ("Working on rrd file: %s Failed\n",$datafile_name) if $verbose;
printf ("rrd file: %s not found.\n",$datafile_name) if $verbose;
}
undef @max;
}
$realmax = $max > $absmax ? $max : $absmax;
push (@max, $realmax);
if (defined($dsmax)) {
push (@max,$dsmax)
} else {
$realmax = $max > $absmax ? $max : $absmax;
push (@max, $realmax);
}
$old_device_id = $device_id;
#$old_probe_id = $probe_id;
}
......
......@@ -58,7 +58,11 @@ class DVG_database {
} catch (PDOException $e) {
DVG_error::db($e,$query);
}
return $result;
if ( is_bool($result) && ! $result) {
return NULL;
} else {
return $result;
}
} # }}}
function getRow($dbh,$query) # {{{
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment