]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/scripts/qosd
Wir kehren zurueck zu Kudzu, da hwinfo noch mehr Aerger macht.
[people/teissler/ipfire-2.x.git] / src / scripts / qosd
CommitLineData
a7fb5630
MT
1#!/usr/bin/perl -w
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
MT
49my $device = "$ARGV[0]";
50our $rrd_datadir = "/var/log/rrd/";
a7fb5630
MT
51our $event_datadir = $rrd_datadir;
52our $STEP = 10;
53our $tc_command = "/sbin/tc";
54
55# A trick is to set the environment PERL5LIB to include $GRAPHDIR
56# This is done by the init-script
57# ($GRAPHDIR is obtained from /usr/local/etc/ADSL-optimizer.conf)
58my $include_dir = '/var/ipfire/qos/bin';
59
60
61# Create the $rrd_datadir if it doesn't exists
62if ( ! -d $rrd_datadir ) {
63 print "RRD-datadir not found, creating it: $rrd_datadir \n";
64 my $status = system("mkdir $rrd_datadir");
65 die "\nERROR cannot create \"$rrd_datadir\"\n" unless $status == 0;
66}
67
68# use POSIX;
69#
70#POSIX::setsid()
71# or die "Can't become a daemon: $!";
72
73# The init scripts will do the right "daemon" thing...
74# Become a daemon
75print "Becoming a daemon...\n";
76my $pid = fork;
77exit if $pid;
78die "Couldn't fork: $!" unless defined($pid);
79
80my $time_to_die = 0;
81sub signal_handler {
82 $time_to_die = 1;
83}
84# Trap signals
85$SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
86$SIG{PIPE} = 'IGNORE';
87
88our %classes_data;
89our %classes_info;
90require "$include_dir/parse-func.pl";
91require "$include_dir/event-func.pl";
92require "$include_dir/RRD-func.pl";
93
94until ($time_to_die) {
95
96 #print "Parsing tc statistics on $device\n";
97 my $res = parse_class($device);
98 if ( ! $res ) {
99 print " Error when parsing classes on $device\n";
100 }
101
102 #print "Updating RRD data-files\n";
103 $res = update_rrds();
104 #if ( $res ) {
105 # print " Error updating RRDs: \"$res\"\n";
106 #}
107
108 process_events();
109
110# my $timestamp = time;
111# print "$timestamp\n";
112
113 sleep($STEP);
114}
115
116print "tc-collector daemon exiting ... bye bye!\n";