]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/qosd
3 step in tuning 2.3
[people/pmueller/ipfire-2.x.git] / src / scripts / qosd
1 #!/usr/bin/perl -w
2 use strict;
3
4 ##########################################
5 ##
6 ## DESCRIPTION
7 ##
8 ## The tc-graph daemon script: "tc-collector"
9 ## Which is part of the ADSL-optimizer.
10 ##
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.
15 ##
16 ## GRAPHs
17 ##
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').
22 ##
23 ## drraw: http://web.taranis.org/drraw/
24 ##
25 ##
26 ## REQUIRES
27 ##
28 ## RRDtools Perl interface RRDs
29 ## The "tc" command.
30 ##
31 ##
32 ## AUTHOR
33 ## Jesper Dangaard Brouer <hawk@diku.dk>, d.16/4-2004
34 ##
35 ## CHANGELOG
36 ## 2004-04-16: Initial version.
37 ## 2004-05-27: Daemon version.
38 ##
39 ## $Id: tc-collector.pl,v 1.12 2005/03/19 19:31:08 hawk Exp $
40 ##########################################
41
42 # TODO:
43 # * Calc time used to parse, use to make time steps more precise
44 # * Device list support
45 # * Detecting the correct devices
46
47 # Configuration options:
48 #
49 my $device = "$ARGV[0]";
50
51 my %mainsettings = ();
52 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
53
54 our $event_datadir = $mainsettings{'RRDLOG'};
55 our $STEP = 10;
56 our $tc_command = "/sbin/tc";
57
58 # A trick is to set the environment PERL5LIB to include $GRAPHDIR
59 # This is done by the init-script
60 # ($GRAPHDIR is obtained from /usr/local/etc/ADSL-optimizer.conf)
61 my $include_dir = '/var/ipfire/qos/bin';
62
63
64 # Create the $mainsettings{'RRDLOG'} if it doesn't exists
65 if ( ! -d $mainsettings{'RRDLOG'} ) {
66 print "RRD-datadir not found, creating it: $mainsettings{'RRDLOG'} \n";
67 my $status = system("mkdir $mainsettings{'RRDLOG'}");
68 die "\nERROR cannot create \"$mainsettings{'RRDLOG'}\"\n" unless $status == 0;
69 }
70
71 # use POSIX;
72 #
73 #POSIX::setsid()
74 # or die "Can't become a daemon: $!";
75
76 # The init scripts will do the right "daemon" thing...
77 # Become a daemon
78 print "Becoming a daemon...\n";
79 my $pid = fork;
80 exit if $pid;
81 die "Couldn't fork: $!" unless defined($pid);
82
83 my $time_to_die = 0;
84 sub signal_handler {
85 $time_to_die = 1;
86 }
87 # Trap signals
88 $SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
89 $SIG{PIPE} = 'IGNORE';
90
91 our %classes_data;
92 our %classes_info;
93 require "$include_dir/parse-func.pl";
94 require "$include_dir/event-func.pl";
95 require "$include_dir/RRD-func.pl";
96
97 until ($time_to_die) {
98
99 #print "Parsing tc statistics on $device\n";
100 my $res = parse_class($device);
101 if ( ! $res ) {
102 print " Error when parsing classes on $device\n";
103 }
104
105 #print "Updating RRD data-files\n";
106 $res = update_rrds();
107 #if ( $res ) {
108 # print " Error updating RRDs: \"$res\"\n";
109 #}
110
111 process_events();
112
113 # my $timestamp = time;
114 # print "$timestamp\n";
115
116 sleep($STEP);
117 }
118
119 print "tc-collector daemon exiting ... bye bye!\n";