Ok.. I'll recap.
All the graphs are generated in the script via simple calls to a gnuplot binary. No Perl modules used at all. We've been using gnuplot for a long time where I work, so, we've managed to both find good ways of wrangling it, and find ways of making it pretty. It's a clever little bit of code.. Have a look:
open (GNUPLOT, "|gnuplot 2>/dev/null 1>/dev/null");
print GNUPLOT <<EOF;
set term png transparent size 1000,220 x000000 xaaaaaa x202020 x90
+9090 x88ff88 xffffff xfffffe x000000 x505050
set title "Halogen: Number of pSeries Systems Exceeding CPU Panic
+Threshold \(Starting: $rangeStart Ending: $rangeEnd\)" textcolor lt 2
set output "/var/www/html/spectrum/halogen-spectrum.png"
set mxtics 2
set xtics 300
set grid
unset key
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%H:%M"
set yrange ["$yNeg" : "$yPos"]
set xrange ["$rangeStart" : "$rangeEnd"]
set pointsize 0.9
set multiplot
plot "/var/www/html/halogen/data.txt" using 1:3 w linespoints lt 6
+ pt 7, "/var/www/html/halogen/data.txt" using 1:3 smooth bezier w lin
+es lw 1 lt 2
EOF
close (GNUPLOT);
In Perl, we're basically opening a pipe to the gnuplot command and funneling it the native command syntax it understands...The print call will continue until an EOF is received. When it hits EOF, the print call closes, we close the pipe, the binary kicks off, and whammo, you've got a graph sitting in a filesystem ready to go.
We've even managed to get our graphs to look fairly anti-aliased, something which stock gnuplot doesn't support (without being compiled against libgd/cairo libraries, at least)...All you do is just generate the graph at a resolution higher than you expect to see it on a webpage..and make sure the img tag used for the graph is hard-coded with a specific width or height smaller than the physical resolution of the image, and the browser handles the task of doing a quick cubic downscaling of the image. Looks much better that way.
Cheers, Bowie |