Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # $id: Daniel Hilst, danielhilst at gmail.com
- # Description:
- # This script will read rddinfo output and generate
- # the rrdcreate line needed to create that file. So
- # you can change parameters and recreate the file
- #
- # @TODO: Remove old redundant code.
- #
- use warnings;
- use strict;
- use Data::Dumper;
- my $dss_index = 0;
- my $rrd = {
- filename => undef,
- step => undef,
- dss_ar => [],
- dss => {},
- rras => [],
- };
- while (<>) {
- chomp;
- # print $_, "\n";
- if (/filename = "(.+)"/) {
- $rrd->{filename} = $1;
- }
- if (/step = (\d+)/) {
- $rrd->{step} = $1;
- } elsif (/ds\[(\w+)\]/) {
- my $ds = $1;
- unless ($rrd->{dss}->{$ds}) {
- $rrd->{dss}->{$ds} = {};
- $rrd->{dss_ar}->[$dss_index] = $rrd->{dss}->{$ds};
- $dss_index++;
- }
- $rrd->{dss}->{$ds}->{ds_name} = $ds;
- if (/ds\[\w+\]\.type = "(\w+)"/) {
- my $type = $1;
- $rrd->{dss}->{$ds}->{type} = $type;
- }
- if (/ds\[\w+\]\.minimal_heartbeat = (\d+)/) {
- $rrd->{dss}->{$ds}->{minimal_heartbeat} = $1;
- }
- if (/ds\[\w+\]\.min = (.+)/) {
- my $min = $1;
- $min = sprintf("%f", $min);
- $min = "U" if $min =~ /nan/;
- $rrd->{dss}->{$ds}->{min} = $min;
- }
- if (/ds\[\w+\]\.max = (.+)/) {
- my $max = $1;
- $max = sprintf("%f", $max);
- $max = "U" if $max =~ /nan/;
- $rrd->{dss}->{$ds}->{max} = $max;
- }
- # print "DS[$ds] => ", $_, "\n"
- } elsif (/rra\[(\d+)\]/) {
- my $i = $1;
- $rrd->{rras}->[$i] = {} unless $rrd->{rras}->[$i];
- if (/rra\[\d+\].cf = ("\w+")/) {
- $rrd->{rras}->[$i]->{cf} = $1;
- }
- if (/rra\[\d+\].rows = (\w+)/) {
- $rrd->{rras}->[$i]->{rows} = $1;
- }
- if (/rra\[\d+\].pdp_per_row = (\w+)/) {
- $rrd->{rras}->[$i]->{pdp_per_row} = $1;
- }
- if (/rra\[\d+\].xff = (.+)/) {
- my $xff = $1;
- $xff = sprintf("%f", $xff);
- $rrd->{rras}->[$i]->{xff} = $xff;
- }
- # print "RRA => ", $_, "\n"
- }
- }
- #print Dumper($rrd);
- my $cline = "rrdtool create \"" . $rrd->{filename} . "\" --step " . $rrd->{step} . " \\\n";
- for my $ds (@{ $rrd->{dss_ar} }) {
- my $ds_name = $ds->{ds_name};
- $cline .= " DS:" . $ds_name . ":" . $rrd->{dss}->{$ds_name}->{type} . ":" . $rrd->{dss}->{$ds_name}->{minimal_heartbeat} . ":" . $rrd->{dss}->{$ds_name}->{min} . ":" . $rrd->{dss}->{$ds_name}->{max} . " \\\n";
- }
- for my $rra (@{$rrd->{rras}}) {
- $cline .= " RRA:" . $rra->{cf} . ":" . $rra->{xff} . ":" . $rra->{pdp_per_row} . ":" . $rra->{rows} . " \\\n";
- }
- print $cline, "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement