]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/qosd
64a341322e50e4f5611b1a138f4931f104b4711f
[ipfire-2.x.git] / src / scripts / qosd
1 #!/usr/bin/perl -w
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 # Configuration options:
25 #
26 my $device = "$ARGV[0]";
27
28 our %mainsettings = ();
29 require '/var/ipfire/general-functions.pl';
30 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
31
32 our $rrd_datadir = $mainsettings{'RRDLOG'}."/";
33 our $event_datadir = $mainsettings{'RRDLOG'};
34 our $STEP = 10;
35 our $tc_command = "/sbin/tc";
36
37 # A trick is to set the environment PERL5LIB to include $GRAPHDIR
38 # This is done by the init-script
39 # ($GRAPHDIR is obtained from /usr/local/etc/ADSL-optimizer.conf)
40 my $include_dir = '/var/ipfire/qos/bin';
41
42
43 # Create the $mainsettings{'RRDLOG'} if it doesn't exists
44 if ( ! -d $mainsettings{'RRDLOG'} ) {
45 print "RRD-datadir not found, creating it: $mainsettings{'RRDLOG'} \n";
46 my $status = system("mkdir $mainsettings{'RRDLOG'}");
47 die "\nERROR cannot create \"$mainsettings{'RRDLOG'}\"\n" unless $status == 0;
48 }
49
50 # use POSIX;
51 #
52 #POSIX::setsid()
53 # or die "Can't become a daemon: $!";
54
55 # The init scripts will do the right "daemon" thing...
56 # Become a daemon
57 print "Becoming a daemon...\n";
58 my $pid = fork;
59 exit if $pid;
60 die "Couldn't fork: $!" unless defined($pid);
61
62 my $time_to_die = 0;
63 sub signal_handler {
64 $time_to_die = 1;
65 }
66 # Trap signals
67 $SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
68 $SIG{PIPE} = 'IGNORE';
69
70 our %classes_data;
71 our %classes_info;
72 require "$include_dir/parse-func.pl";
73 require "$include_dir/event-func.pl";
74 require "$include_dir/RRD-func.pl";
75
76 until ($time_to_die) {
77
78 #print "Parsing tc statistics on $device\n";
79 my $res = parse_class($device);
80 if ( ! $res ) {
81 print " Error when parsing classes on $device\n";
82 }
83
84 #print "Updating RRD data-files\n";
85 $res = update_rrds();
86 #if ( $res ) {
87 # print " Error updating RRDs: \"$res\"\n";
88 #}
89
90 # my $timestamp = time;
91 # print "$timestamp\n";
92
93 sleep($STEP);
94 }
95
96 print "tc-collector daemon exiting ... bye bye!\n";