]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/scripts/qosd
media.cgi: Fix typo 'writen'.
[people/teissler/ipfire-2.x.git] / src / scripts / qosd
CommitLineData
bcad0fd0 1#!/usr/bin/perl -w
a7fb5630
MT
2use 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#
7ccede9b 49my $device = "$ARGV[0]";
bcad0fd0 50
1c163c04
CS
51our %mainsettings = ();
52require '/var/ipfire/general-functions.pl';
bcad0fd0
CS
53&General::readhash("${General::swroot}/main/settings", \%mainsettings);
54
1c163c04 55our $rrd_datadir = $mainsettings{'RRDLOG'}."/";
bcad0fd0 56our $event_datadir = $mainsettings{'RRDLOG'};
a7fb5630
MT
57our $STEP = 10;
58our $tc_command = "/sbin/tc";
59
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)
63my $include_dir = '/var/ipfire/qos/bin';
64
65
bcad0fd0
CS
66# Create the $mainsettings{'RRDLOG'} if it doesn't exists
67if ( ! -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;
a7fb5630
MT
71}
72
73# use POSIX;
74#
bcad0fd0 75#POSIX::setsid()
a7fb5630
MT
76# or die "Can't become a daemon: $!";
77
78# The init scripts will do the right "daemon" thing...
bcad0fd0 79# Become a daemon
a7fb5630
MT
80print "Becoming a daemon...\n";
81my $pid = fork;
82exit if $pid;
83die "Couldn't fork: $!" unless defined($pid);
84
85my $time_to_die = 0;
86sub signal_handler {
87 $time_to_die = 1;
88}
89# Trap signals
90$SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
91$SIG{PIPE} = 'IGNORE';
92
93our %classes_data;
94our %classes_info;
95require "$include_dir/parse-func.pl";
bcad0fd0 96require "$include_dir/event-func.pl";
a7fb5630
MT
97require "$include_dir/RRD-func.pl";
98
99until ($time_to_die) {
100
101 #print "Parsing tc statistics on $device\n";
102 my $res = parse_class($device);
103 if ( ! $res ) {
104 print " Error when parsing classes on $device\n";
105 }
106
107 #print "Updating RRD data-files\n";
108 $res = update_rrds();
109 #if ( $res ) {
110 # print " Error updating RRDs: \"$res\"\n";
111 #}
bcad0fd0 112
a7fb5630
MT
113# my $timestamp = time;
114# print "$timestamp\n";
bcad0fd0 115
a7fb5630
MT
116 sleep($STEP);
117}
118
119print "tc-collector daemon exiting ... bye bye!\n";