[rrd-users] Outputting a PNG directly from Perl + RRDs.pm

Chris Snell cjs at citysearch.com
Fri Jan 14 01:15:50 MET 2000


Hi,

I'm having trouble getting a perl program (using the RRDs module) to output 
a PNG directly.   What I would like to be able to do is create a CGI script 
(running under mod_perl) that will spit out "Content-type: image/png" 
followed by a graph.  I'm going to eventually call it like this within HTML:

	<IMG SRC="/mp-bin/graphgen?host=utah.citysearch.com">

and it would spit out a graph for the "host".

The problem is, I can't seem to make the perl module spit out an image 
directly.  It seems to want to write it to a file instead.  I tried using 
"-" as a filename but it didn't spit out anything.  Any ideas?

Here's what I have so far:

package SLUG::Slime;
# File: SLUG/Slime.pm

use strict;
use Apache;
use Apache::Constants qw( :common :response );

# The Shared RRDtool module
use RRDs;

sub handler {
         # get request object
         my $r = shift;
         my $RRD_FILES = "/opt/slug/rrd_files";
         $r->content_type('image/png');
         my ($graphret,$xsize,$ysize) = RRDs::graph "-", "--title",
         'SFOCA Real Server Sessions', '--vertical-label', 'SESSIONS',
         '--start', '-65000',
         "DEF:ireland=${RRD_FILES}/sfoca27i-sessions.rrd:sfoca27i:AVERAGE",
         "DEF:nantucket=${RRD_FILES}/sfoca27n-sessions.rrd:sfoca27n:AVERAGE",
         "LINE2:ireland#215e21:ireland",
         "LINE2:nantucket#ff0000:nantucket";
         return OK;
}

# all modules succeed
1;

__END__
--
Chris Snell <cjs at citysearch.com>         626.660.2882 W
UNIX Wrangler                            626.695.1747 M
Ticketmaster Online - CitySearch, Inc.     Pasadena, CA

"You know, it's the early bird that gets the worm...
        But it's the second mouse that gets the cheese."
              - Guy Clark

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users



More information about the rrd-users mailing list