]>
Commit | Line | Data |
---|---|---|
bcad0fd0 | 1 | #!/usr/bin/perl -w |
66c36198 PM |
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 | ############################################################################### | |
a7fb5630 | 21 | |
66c36198 | 22 | use strict; |
a7fb5630 MT |
23 | |
24 | # Configuration options: | |
25 | # | |
7ccede9b | 26 | my $device = "$ARGV[0]"; |
bcad0fd0 | 27 | |
1c163c04 CS |
28 | our %mainsettings = (); |
29 | require '/var/ipfire/general-functions.pl'; | |
bcad0fd0 CS |
30 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); |
31 | ||
1c163c04 | 32 | our $rrd_datadir = $mainsettings{'RRDLOG'}."/"; |
bcad0fd0 | 33 | our $event_datadir = $mainsettings{'RRDLOG'}; |
a7fb5630 MT |
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 | ||
bcad0fd0 CS |
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; | |
a7fb5630 MT |
48 | } |
49 | ||
50 | # use POSIX; | |
51 | # | |
bcad0fd0 | 52 | #POSIX::setsid() |
a7fb5630 MT |
53 | # or die "Can't become a daemon: $!"; |
54 | ||
55 | # The init scripts will do the right "daemon" thing... | |
bcad0fd0 | 56 | # Become a daemon |
a7fb5630 MT |
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"; | |
bcad0fd0 | 73 | require "$include_dir/event-func.pl"; |
a7fb5630 MT |
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 | #} | |
bcad0fd0 | 89 | |
a7fb5630 MT |
90 | # my $timestamp = time; |
91 | # print "$timestamp\n"; | |
bcad0fd0 | 92 | |
a7fb5630 MT |
93 | sleep($STEP); |
94 | } | |
95 | ||
96 | print "tc-collector daemon exiting ... bye bye!\n"; |