Skip to content

Instantly share code, notes, and snippets.

@jvehent
Created November 2, 2011 16:41
Show Gist options
  • Save jvehent/1334149 to your computer and use it in GitHub Desktop.
Save jvehent/1334149 to your computer and use it in GitHub Desktop.
rrds::create with unknown list of datasources
# define a list of HTB classes to check
# the order matters, because of the RRD database
my @class_list=(100,200,300,400,999);
[..... truncated .... ]
my $datasources = "";
for my $class (0 .. $#class_list){
$datasources .= "DS:$class_list[$class]:$storage_type:". $updatefreq * 10 .":0:U";
$datasources .= ",\n" unless ($class == $#class_list);
}
# datasource will contain
# DS:100:COUNTER:600:0:U,DS:200:COUNTER:600:0:U,DS:300:COUNTER:600:0:U,DS:400:COUNTER:600:0:U,DS:999:COUNTER:600:0:U
print $datasources."\n";
RRDs::create($rrd_file,
"--start now",
"--step=$updatefreq", #data collection interval
"$datasources",
# 7 days of detailled records
"RRA:AVERAGE:0.5:1:".(7 * $day / $updatefreq). "",
"RRA:MAX:0.5:1:".(7 * $day / $updatefreq). "",
"RRA:LAST:0.5:1:1", # "last" value
# 1 record per hour for 60 days (1440 hours)
"RRA:AVERAGE:0.5:".($hour / $updatefreq).":1440",
"RRA:MAX:0.5:".($hour / $updatefreq).":1440",
# 1 record per 12 hours for 1 year (366 * 2 = 732 records)
"RRA:AVERAGE:0.5:".($day / 2 / $updatefreq).":732",
"RRA:MAX:0.5:".($day / 2 / $updatefreq).":732"
) or die "RRD Create error: $!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment