]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/qosd
4 ##########################################
8 ## The tc-graph daemon script: "tc-collector"
9 ## Which is part of the ADSL-optimizer.
11 ## The script will become a daemon and periodically collect data
12 ## from the Linux traffic control system. The collected data is
13 ## stored in some RRD-data files, which is created automatically by
14 ## the script if they don't exist.
18 ## How the RRD-data is displayed as graphs is not part of the
19 ## tc-collector tool. But we recommend using the RRD-frontend 'ddraw'.
20 ## We have included some 'ddraw' examples (which is hardcoded to use
21 ## files from '/var/spool/rrdqueues').
23 ## drraw: http://web.taranis.org/drraw/
28 ## RRDtools Perl interface RRDs
33 ## Jesper Dangaard Brouer <hawk@diku.dk>, d.16/4-2004
36 ## 2004-04-16: Initial version.
37 ## 2004-05-27: Daemon version.
39 ## $Id: tc-collector.pl,v 1.12 2005/03/19 19:31:08 hawk Exp $
40 ##########################################
43 # * Calc time used to parse, use to make time steps more precise
44 # * Device list support
45 # * Detecting the correct devices
47 # Configuration options:
49 my $device = "$ARGV[0]";
51 our %mainsettings = ();
52 require '/var/ipfire/general-functions.pl';
53 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
55 our $rrd_datadir = $mainsettings{'RRDLOG'}."/";
56 our $event_datadir = $mainsettings{'RRDLOG'};
58 our $tc_command = "/sbin/tc";
60 # A trick is to set the environment PERL5LIB to include $GRAPHDIR
61 # This is done by the init-script
62 # ($GRAPHDIR is obtained from /usr/local/etc/ADSL-optimizer.conf)
63 my $include_dir = '/var/ipfire/qos/bin';
66 # Create the $mainsettings{'RRDLOG'} if it doesn't exists
67 if ( ! -d
$mainsettings{'RRDLOG'} ) {
68 print "RRD-datadir not found, creating it: $mainsettings{'RRDLOG'} \n";
69 my $status = system("mkdir $mainsettings{'RRDLOG'}");
70 die "\nERROR cannot create \"$mainsettings{'RRDLOG'}\"\n" unless $status == 0;
76 # or die "Can't become a daemon: $!";
78 # The init scripts will do the right "daemon" thing...
80 print "Becoming a daemon...\n";
83 die "Couldn't fork: $!" unless defined($pid);
90 $SIG{INT
} = $SIG{TERM
} = $SIG{HUP
} = \
&signal_handler
;
91 $SIG{PIPE
} = 'IGNORE';
95 require "$include_dir/parse-func.pl";
96 require "$include_dir/event-func.pl";
97 require "$include_dir/RRD-func.pl";
99 until ($time_to_die) {
101 #print "Parsing tc statistics on $device\n";
102 my $res = parse_class
($device);
104 print " Error when parsing classes on $device\n";
107 #print "Updating RRD data-files\n";
108 $res = update_rrds
();
110 # print " Error updating RRDs: \"$res\"\n";
113 # my $timestamp = time;
114 # print "$timestamp\n";
119 print "tc-collector daemon exiting ... bye bye!\n";