]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/qos/RRD-func.pl
2 ##########################################
6 ## RRD function for tc-graph.
7 ## Which is part of the ADSL-optimizer.
13 ## Jesper Dangaard Brouer <hawk@diku.dk>, d.15/4-2004
16 ## 2004-04-15: Initial version.
18 ## $Id: RRD-func.pl,v 1.10 2004/05/27 17:02:12 hawk Exp $
19 ##########################################
23 if (not defined $STEP) {
27 my $heartbeat=$STEP*2;
29 # Update script samples every 10 seconds.
30 # 24*60*60 = 86400 seconds (== one day)
31 # 8640 *10 = 86400 seconds (== one day)
32 # 8640 * 5days = 43200 seconds with 10 sec samples
34 my @rrd_data_sources =
36 "DS:bytes:COUNTER:$heartbeat:0:U",
37 "DS:bits:COUNTER:$heartbeat:0:U",
38 "DS:pkts:COUNTER:$heartbeat:0:U",
39 "DS:dropped:COUNTER:$heartbeat:0:U",
40 "DS:overlimits:COUNTER:$heartbeat:0:U",
41 "DS:lended:COUNTER:$heartbeat:0:U",
42 "DS:borrowed:COUNTER:$heartbeat:0:U",
43 "DS:giants:COUNTER:$heartbeat:0:U",
44 "DS:backlog:GAUGE:$heartbeat:0:U",
45 "RRA:AVERAGE:0.5:1:43200",
46 "RRA:AVERAGE:0.5:7:8640",
47 "RRA:AVERAGE:0.5:31:8640",
48 "RRA:AVERAGE:0.5:372:8640",
50 "RRA:MAX:0.5:31:8640",
51 "RRA:MAX:0.5:372:8640"
55 sub get_filename_rrd
($) {
56 my $class_device = "$_[0]";
57 my $filename = "${rrd_datadir}class_${class_device}.rrd";
61 sub create_rrdfile
($) {
62 my $class_device = "$_[0]";
63 my $filename = get_filename_rrd
($class_device);
64 RRDs
::create
$filename, @rrd_data_sources;
65 my $ERROR = RRDs
::error
;
68 die "$timestamp: ERROR - Unable to create RRDfile \"$filename\": $ERROR\n";
72 sub format_class_data
($) {
74 my ($rrd_template, $rrd_data);
75 my (@array_template, @array_data);
76 #print "Ref:". ref($class) ."\n";
78 # Select and correct undef values and key
79 while ( (my $key, my $value) = each %{$class}) {
81 if ( ($key eq "last_update") ||
82 ($key eq "file_update") ||
83 ($key =~ /hfsc_/ )) {next}
85 push @array_template, $key;
87 if ( (not defined $value) ||
91 push @array_data, $value;
94 # Makes a RRD suitable input format
95 $rrd_template = join(":",@array_template);
96 $rrd_data = join(":",@array_data);
98 return ($rrd_template, $rrd_data);
105 my @test = keys %classes_data;
107 print time, " [update_rrds] WARNING: classes_data empty!\n";
108 return "classes_data empty";
111 # Find the class_device (keys) in %classes_data
112 for my $class_device ( keys %classes_data ) {
114 if ("last_update" eq "$class_device") {next}
116 # Verify file exist (else create it)
117 my $filename = get_filename_rrd
($class_device);
118 if ( ! -f
$filename ) {
119 print "Creating RRDfile: $filename\n";
120 create_rrdfile
($class_device);
122 #print "$class_device\n";
124 # Make a RRD suitable input format
125 my ($rrd_template, $rrd_data) = format_class_data
($classes_data{$class_device});
126 #print "rrd_template: $rrd_template\n";
127 #print "rrd_data: $rrd_data\n";
131 # $classes_data{$device}{last_update} ????
132 my ($tmp, $device) = split /_/, $class_device;
133 #print "device: $device $classes_data{last_update}{$device} \n";
134 if ( (exists $classes_data{last_update
}{$device}) ) {
135 if ((($classes_data{$class_device}{last_update
} + $heartbeat) <
136 $classes_data{last_update
}{$device})) {
137 print "WARNING: the class $class_device was";
138 print "not updated in lastrun + heartbeat...\n";
139 print "Assuming $class_device is removed,";
140 print " thus deleteing from hash table.";
141 # # ??? MAYBE DELETE THE OLD HASH ???
142 $res="Deleting class $class_device";
143 for my $key ( keys %{ $classes_data{$class_device} } ) {
144 delete( $classes_data{$class_device}{$key});
145 print " Deleting key: $key from: $class_device \n";
147 delete $classes_data{$class_device};
152 # Verifies that it is new data,
153 # and not old data which already have been updated
155 # print "$0 FIXME update_rrds \n";
156 if ( exists $classes_data{$class_device}{file_update
} ) {
157 if (($classes_data{$class_device}{file_update
} >=
158 $classes_data{$class_device}{last_update
})) {
159 print "Warning ($class_device):";
160 print " data already updated... old data or deleted class?\n";
161 $res="Old data or deleted class";
162 # ??? MAYBE DELETE THE OLD HASH ???
168 # Update the RRD file
169 my $update_time = $classes_data{$class_device}{last_update
};
170 # print "Updates: $filename time:$update_time\n";
171 # print " --template=$rrd_template\n";
172 # print " $update_time:$rrd_data\n";
174 # `rrdtool update $filename --template=$rrd_template $update_time:$rrd_data`;
175 RRDs
::update
($filename, "--template=$rrd_template",
178 my $ERROR = RRDs
::error
;
180 my $timestamp = time;
181 print "$timestamp: WARNING - ";
182 print "Unable to update RRDfile \"$filename\": $ERROR\n";
183 $res="Unable to update RRDfile \"$filename\"";
185 $classes_data{$class_device}{file_update
} = time;