7 use FindBin ('$RealBin');
8 use Carp (qw(confess cluck));
12 use Collectd::Graph::TypeLoader (qw(tl_read_config tl_load_type));
14 use Collectd::Graph::Common (qw(sanitize_type get_selected_files
16 use Collectd::Graph::Type ();
18 our $Debug = param ('debug');
19 our $Begin = param ('begin');
20 our $End = param ('end');
21 our $GraphWidth = param ('width');
26 Content-Type: text/plain
31 tl_read_config ("$RealBin/../etc/collection.conf");
33 { # Sanitize begin and end times
42 if (!$Begin || !($Begin =~ m/^-?([1-9][0-9]*)$/))
51 $Begin = $End + $Begin;
55 $Begin = time () + $Begin;
61 $Begin = time () - 86400;
64 if (($End > 0) && ($Begin > $End))
72 my $type = param ('type') or die;
75 $obj = tl_load_type ($type);
78 confess ("tl_load_type ($type) failed");
81 $type = ucfirst (lc ($type));
82 $type =~ s/_([A-Za-z])/\U$1\E/g;
83 $type = sanitize_type ($type);
85 my $files = get_selected_files ();
89 print STDOUT Data::Dumper->Dump ([$files], ['files']);
96 my $expires = time ();
98 # OR (Begin is before `now' AND End is after `now')
99 if (($End == 0) || (($Begin <= $expires) && ($End >= $expires)))
101 # 400 == width in pixels
106 $timespan = $expires - $Begin;
110 $timespan = $End - $Begin;
112 $expires += int ($timespan / 400.0);
114 # IF (End is not `now')
115 # AND (End is before `now')
116 # ==> Graph will never change again!
117 elsif (($End > 0) && ($End < $expires))
119 $expires += (366 * 86400);
121 elsif ($Begin > $expires)
126 print STDOUT header (-Content_type => 'image/png',
127 -Last_Modified => epoch_to_rfc1123 ($obj->getLastModified ()),
128 -Expires => epoch_to_rfc1123 ($expires));
132 print "\$expires = $expires;\n";
135 my $args = $obj->getRRDArgs (0);
139 require Data::Dumper;
140 print STDOUT Data::Dumper->Dump ([$obj], ['obj']);
141 print STDOUT join (",\n", @$args) . "\n";
142 print STDOUT "Last-Modified: " . epoch_to_rfc1123 ($obj->getLastModified ()) . "\n";
148 if ($End) # $Begin is always true
150 @timesel = ('-s', $Begin, '-e', $End);
154 @timesel = ('-s', $Begin); # End is implicitely `now'.
158 RRDs::graph ('-', '-a', 'PNG', @timesel, @$args);
159 if (my $err = RRDs::error ())
161 print STDERR "RRDs::graph failed: $err\n";
168 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :