#!/usr/bin/perl # Generate Graphs exported from Makegraphs to minimize system load an only generate the Graphs when displayed ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2005-2010 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### package Graphs; use strict; use RRDs; use experimental 'smartmatch'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; # Graph image size in pixel our %image_size = ('width' => 910, 'height' => 300); # List of all available time ranges our @time_ranges = ("hour", "day", "week", "month", "year"); my $ERROR; my @GRAPH_ARGS = ( # Output format "--imgformat", "SVG", # No border "--border", "0", # For a more 'organic' look "--slope-mode", # HxW define the size of the output image "--full-size-mode", # Watermark "-W www.ipfire.org", # Default size "-w $image_size{'width'}", "-h $image_size{'height'}", # Use alternative grid "--alt-y-grid", ); my %color = (); my %mainsettings = (); my %sensorsettings = (); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); if ( $mainsettings{'RRDLOG'} eq "" ){ $mainsettings{'RRDLOG'}="/var/log/rrd"; &General::writehash("${General::swroot}/main/settings", \%mainsettings); } # If the collection deamon is working and collecting lm_sensors data there will be # some data source named after a common scheme, with the sensorssettingsfile # the user is able to deactivate some of this parameters, in case not to show # false collected values may be disable. The user has the ability to enter # custom graph names in order to change temp0 to cpu or motherboard my $count = 0; my @sensorsgraphs = (); my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/ 2>/dev/null`; foreach (@sensorsdir){ chomp($_);chop($_); foreach (`ls $_/*`){ chomp($_); push(@sensorsgraphs,$_); $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; my $label = $2.$3;$label=~ s/-//g; $sensorsettings{'LABEL-'.$label}="$label"; $sensorsettings{'LINE-'.$label}="checked"; } } &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings); # Generate a nice box for selection of time range in graphs # this will generate a nice div box for the cgi every klick for # the graph will be handled by javascript # 0 is the cgi refering to # 1 is the graph name # 2 is the time range for the graph (optional) sub makegraphbox { my ($origin, $name, $default_range) = @_; # Optional time range: Default to "day" unless otherwise specified $default_range = "day" unless ($default_range ~~ @time_ranges); print <