[rrd-developers] Utility - rrddescribe.pl
bill george
wjgeorge7 at yahoo.com
Thu Jun 3 05:54:11 MEST 2004
This is a hunk-o-code to display information about an
RRD file in two format:
1) rrdtool format
Output is the rrdtool command that can be used
create the RRD. Usage is "perl rrddescribe.pl files"
2) "English"
An English version (sort of) the configuration for
an RRD file. Other languages welcome. Usage is "perl
rrddescribe.pl -e files"
I don't know where to post this, so I'll post it here
(its small). Feedback and corrections requested.
Bill George
Vonage Operation
--------------------------------
use strict;
use RRDs;
use Getopt::Std;
use Time::localtime;
getopts("dve");
our($opt_d, $opt_v, $opt_e);
my $step;
for (my $i=0; $i <= $#ARGV; $i++) {
my $file = $ARGV[$i];
my $hash = RRDs::info $file;
my $ERR=RRDs::error;
die "ERROR getting info: $ERR\n" if $ERR;
if ($opt_e) {
print "From file: $$hash{filename}\n";
} else {
print "rrdtool create $$hash{filename}";
}
# get the DS names for this file
my ($start,$step,$names,$data) =
RRDs::fetch($file,"AVERAGE","--start","now","--end","start+1");
$ERR=RRDs::error;
die "ERROR geting names: $ERR\n" if $ERR;
# start
if ($opt_e) {
print "On or after
".ctime($$hash{last_update})."\n";
} else {
print " --start $$hash{last_update}";
}
# step
$step = $$hash{step};
if ($opt_e) {
print "Poll every ".roundme($step)."\n";
} else {
print " --step $step" unless $step == 300;
}
# DSs
foreach my $j (@$names) {
my $key="ds[$j]";
my $min = $$hash{$key.'.min'};
my $max = $$hash{$key.'.max'};
if ($opt_e) {
$min = "Undefined" unless defined($min);
$max = "Undefined" unless defined($max);
} else {
$min = "U" unless defined($min);
$max = "U" unless defined($max);
}
if ($opt_e) {
print " Dataset $j is type
$$hash{$key.'.type'}\n\theartbeat is
".roundme($$hash{$key.'.minimal_heartbeat'})."\n\tMinimum
allowed value is $min\n\tMaximum allowed value is
$max\n";
} else {
print "
DS:$j:$$hash{$key.'.type'}:$$hash{$key.'.minimal_heartbeat'}:$min:$max";
}
}
# RRAs
for (my $j=0;;$j++) {
my $key="rra[$j]";
my $bucketsize = $$hash{$key.'.pdp_per_row'};
my $rows= $$hash{$key.'.rows'};
last unless defined($$hash{$key.'.cf'});
if ($opt_e) {
print " Round Robin Archive #$j
CF=$$hash{$key.'.cf'}
XFF=$$hash{$key.'.xff'}\n\t".roundme($step*$bucketsize,"$bucketsize
samples")." stored for
".roundme($step*$bucketsize*$rows,"$rows rows")."\n";
} else {
print "
RRA:$$hash{$key.'.cf'}:$$hash{$key.'.xff'}:$bucketsize}:$rows";
}
}
print "\n";
}
sub roundme {
my ($value,$orig)=@_;
my $hold=$value;
my $mins=60;
my $hours=$mins*60;
my $days=$hours*24;
my $weeks=$days*7;
my $months=$days*30;
my $years=$days*365;
my $str="";
my $mod;
$mod = int($value/$years);
if ($mod) {
$str .= " $mod year";
$value -= $mod*$years;
$str .= "s" if $mod > 1;
}
$mod=int($value/$months);
if ($mod) {
$str .= " $mod month";
$value -= $mod*$months;
$str .= "s" if $mod > 1;
}
$mod=int($value/$weeks);
if ($mod) {
$str .= " $mod week";
$value -= $mod*$weeks;
$str .= "s" if $mod > 1;
}
$mod=int($value/$days);
if ($mod) {
$str .= " $mod day";
$value -= $mod*$days;
$str .= "s" if $mod > 1;
}
$mod=int($value/$hours);
if ($mod) {
$str .= " $mod hour";
$value -= $mod*$hours;
$str .= "s" if $mod > 1;
}
$mod=int($value/$mins);
if ($mod) {
$str .= " $mod minute";
$value -= $mod*$mins;
$str .= "s" if $mod > 1;
}
$str .= " $value second" if ($value);
if (defined($orig)) {
$str .= " ($orig)";
} else {
$str .= " ($hold seconds)";
}
return $str;
}
--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the rrd-developers
mailing list