1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
| #plaatje maken :)
#!/bin/sh
rrdtool graph /home/httpd/html/GoT.png --start -1D -a PNG -w 600 -h 400 -v Byte/s -t Traffic \
DEF:totaalin=totaal.rrd:in:AVERAGE \
"CDEF:totaaldagin=totaalin,86400,*" \
DEF:totaal=totaal.rrd:out:AVERAGE \
"CDEF:totaaldagout=totaal,86400,*" \
"CDEF:totaalout=totaal,-1,*" \
DEF:httpin=http.rrd:in:AVERAGE \
DEF:http=http.rrd:out:AVERAGE \
"CDEF:httpout=http,-1,*" \
DEF:httpserverin=http.rrd:serverin:AVERAGE \
DEF:httpserver=http.rrd:serverout:AVERAGE \
"CDEF:httpserverout=httpserver,-1,*" \
"CDEF:httpdagin=httpin,86400,*" \
"CDEF:httpdagout=http,86400,*" \
"CDEF:httpserverdagin=httpserverin,86400,*" \
"CDEF:httpserverdagout=httpserver,86400,*" \
AREA:httpin#00FFFF:"HTTP In " \
GPRINT:httpin:LAST:"%6.2lf %sB/s" \
GPRINT:httpin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:httpin:MAX:"%6.2lf %sB/s" \
GPRINT:httpdagin:AVERAGE:"%6.2lf %sB\n" \
AREA:httpout#0099FF:"HTTP Out " \
GPRINT:http:LAST:"%6.2lf %sB/s" \
GPRINT:http:AVERAGE:"%6.2lf %sB/s" \
GPRINT:http:MAX:"%6.2lf %sB/s" \
GPRINT:httpdagout:AVERAGE:"%6.2lf %sB\n" \
AREA:httpserverin#00CCFF:"Apache In " \
GPRINT:httpserverin:LAST:"%6.2lf %sB/s" \
GPRINT:httpserverin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:httpserverin:MAX:"%6.2lf %sB/s" \
GPRINT:httpserverdagin:AVERAGE:"%6.2lf %sB\n" \
AREA:httpserverout#0066FF:"Apache Out " \
GPRINT:httpserver:LAST:"%6.2lf %sB/s" \
GPRINT:httpserver:AVERAGE:"%6.2lf %sB/s" \
GPRINT:httpserver:MAX:"%6.2lf %sB/s" \
GPRINT:httpserverdagout:AVERAGE:"%6.2lf %sB\n" \
DEF:dnsin=dns.rrd:in:AVERAGE \
DEF:dns=dns.rrd:out:AVERAGE \
"CDEF:dnsout=dns,-1,*" \
"CDEF:dnsdagin=dnsin,86400,*" \
"CDEF:dnsdagout=dns,86400,*" \
STACK:dnsin#FFFF00:"DNS In " \
GPRINT:dnsin:LAST:"%6.2lf %sB/s" \
GPRINT:dnsin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:dnsin:MAX:"%6.2lf %sB/s" \
GPRINT:dnsdagin:AVERAGE:"%6.2lf %sB\n" \
STACK:dnsout#FF9900:"DNS Out " \
GPRINT:dns:LAST:"%6.2lf %sB/s" \
GPRINT:dns:AVERAGE:"%6.2lf %sB/s" \
GPRINT:dns:MAX:"%6.2lf %sB/s" \
GPRINT:dnsdagout:AVERAGE:"%6.2lf %sB\n" \
DEF:pop3in=pop3.rrd:in:AVERAGE \
DEF:pop3=pop3.rrd:out:AVERAGE \
"CDEF:pop3out=pop3,-1,*" \
"CDEF:pop3dagin=pop3in,86400,*" \
"CDEF:pop3dagout=pop3,86400,*" \
STACK:pop3in#00FF00:"POP3 In " \
GPRINT:pop3in:LAST:"%6.2lf %sB/s" \
GPRINT:pop3in:AVERAGE:"%6.2lf %sB/s" \
GPRINT:pop3in:MAX:"%6.2lf %sB/s" \
GPRINT:pop3dagin:AVERAGE:"%6.2lf %sB\n" \
STACK:pop3out#009900:"POP3 Out " \
GPRINT:pop3:LAST:"%6.2lf %sB/s" \
GPRINT:pop3:AVERAGE:"%6.2lf %sB/s" \
GPRINT:pop3:MAX:"%6.2lf %sB/s" \
GPRINT:pop3dagout:AVERAGE:"%6.2lf %sB\n" \
DEF:smtpin=smtp.rrd:in:AVERAGE \
DEF:smtp=smtp.rrd:out:AVERAGE \
"CDEF:smtpout=smtp,-1,*" \
"CDEF:smtpdagin=smtpin,86400,*" \
"CDEF:smtpdagout=smtp,86400,*" \
STACK:smtpin#FFCCFF:"SMTP In " \
GPRINT:smtpin:LAST:"%6.2lf %sB/s" \
GPRINT:smtpin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:smtpin:MAX:"%6.2lf %sB/s" \
GPRINT:smtpdagin:AVERAGE:"%6.2lf %sB\n" \
STACK:smtpout#FF99FF:"SMTP Out " \
GPRINT:smtp:LAST:"%6.2lf %sB/s" \
GPRINT:smtp:AVERAGE:"%6.2lf %sB/s" \
GPRINT:smtp:MAX:"%6.2lf %sB/s" \
GPRINT:smtpdagout:AVERAGE:"%6.2lf %sB\n" \
DEF:ftpin=ftp.rrd:in:AVERAGE \
DEF:ftp=ftp.rrd:out:AVERAGE \
"CDEF:ftpout=ftp,-1,*" \
"CDEF:ftpdagin=ftpin,86400,*" \
"CDEF:ftpdagout=ftp,86400,*" \
STACK:ftpin#00CC99:"FTP In " \
GPRINT:ftpin:LAST:"%6.2lf %sB/s" \
GPRINT:ftpin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:ftpin:MAX:"%6.2lf %sB/s" \
GPRINT:ftpdagin:AVERAGE:"%6.2lf %sB\n" \
STACK:ftpout#009999:"FTP Out " \
GPRINT:ftp:LAST:"%6.2lf %sB/s" \
GPRINT:ftp:AVERAGE:"%6.2lf %sB/s" \
GPRINT:ftp:MAX:"%6.2lf %sB/s" \
GPRINT:ftpdagout:AVERAGE:"%6.2lf %sB\n" \
DEF:msnin=msn.rrd:in:AVERAGE \
DEF:msn=msn.rrd:out:AVERAGE \
"CDEF:msnout=msn,-1,*" \
"CDEF:msndagin=msnin,86400,*" \
"CDEF:msndagout=msn,86400,*" \
STACK:msnin#99FF00:"MSN In " \
GPRINT:msnin:LAST:"%6.2lf %sB/s" \
GPRINT:msnin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:msnin:MAX:"%6.2lf %sB/s" \
GPRINT:msndagin:AVERAGE:"%6.2lf %sB\n" \
STACK:msnout#99CC00:"MSN Out " \
GPRINT:msn:LAST:"%6.2lf %sB/s" \
GPRINT:msn:AVERAGE:"%6.2lf %sB/s" \
GPRINT:msn:MAX:"%6.2lf %sB/s" \
GPRINT:msndagout:AVERAGE:"%6.2lf %sB\n" \
LINE1:totaalin#000000:"Traffic In " \
GPRINT:totaalin:LAST:"%6.2lf %sB/s" \
GPRINT:totaalin:AVERAGE:"%6.2lf %sB/s" \
GPRINT:totaalin:MAX:"%6.2lf %sB/s" \
GPRINT:totaaldagin:AVERAGE:"%6.2lf %sB\n" \
LINE1:totaalout#000000:"Traffic Out " \
GPRINT:totaal:LAST:"%6.2lf %sB/s" \
GPRINT:totaal:AVERAGE:"%6.2lf %sB/s" \
GPRINT:totaal:MAX:"%6.2lf %sB/s" \
GPRINT:totaaldagout:AVERAGE:"%6.2lf %sB\n"
=========================================================================
# ipfw rules aanmaken
ipfw add 100 count ip from any to any in via isp0 # al het inkomende verkeer via isp0(ISDN-Dial-up)
ipfw add 200 count ip from any to any out via isp0 # al het uitgaande verkeer via isp0(ISDN-Dial-up)
ipfw add 300 count tcp from any 80 to any in via isp0 # al het inkomende http verkeer(answer) via isp0
ipfw add 400 count tcp from any to any 80 out via isp0 # al het uitgaande http verkeer(request) via isp0
ipfw add 500 count tcp from any to any 80 in via isp0 # al het inkomende http verkeer(request) voor webserver via isp0
ipfw add 600 count tcp from any 80 to any out via isp0 # al het uitgaande http verkeer(answer) voor webserver via isp0
ipfw add 700 count tcp from any 25 to any in via isp0 # al het inkomende smtp verkeer(answer) via isp0
ipfw add 800 count tcp from any to any 25 out via isp0 # al het uitgaande smtp verkeer(request) via isp0
ipfw add 1100 count tcp from any 110 to any in via isp0 # al het inkomende pop3 verkeer(answer) via isp0
ipfw add 1200 count tcp from any to any 110 out via isp0 # al het uitgaande pop3 verkeer(request) via isp0
ipfw add 1500 count udp from any 53 to any in via isp0 # al het inkomende dns verkeer(answer) via isp0
ipfw add 1600 count udp from any to any 53 out via isp0 # al het uitgaande dns verkeer(request) via isp0
ipfw add 1900 count tcp from any 21 to any in via isp0 # al het inkomende ftp verkeer(answer) via isp0
ipfw add 2000 count tcp from any to any 21 out via isp0 # al het uitgaande ftp verkeer(request) via isp0
ipfw add 2700 count tcp from any 1863 to any in via isp0 # al het inkomende msn verkeer(answer) via isp0
ipfw add 2800 count tcp from any to any 1863 out via isp0 # al het uitgaande msn verkeer(request) via isp0
=========================================================================
#rrd files aanmaken, ik heb gekozen voor een iets een eigen .rrd file(je kan ook alles in 1 .rrd mikken die word dan wel groot, nu zijn ze 188KB per stuk)
rrdtool create totaal.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create http.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create dns.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create pop3.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create smtp.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create ftp.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
rrdtool create msn.rrd --step 300 DS:in:DERIVE:600:0:U DS:out:DERIVE:600:0:U DS:serverin:DERIVE:600:0:U DS:serverout:DERIVE:600:0:U RRA:MAX:0.5:1:600 RRA:MAX:0.5:6:700 RRA:MAX:0.5:24:775 RRA:MAX:0.5:288:797 RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797
=========================================================================
# script wat de data verzamelt en de .rrd files update(kan ook met de rrd-perl-module)
[erik@piranha ~]# cat traffic.pl
#!/usr/bin/perl
#use RRDs;
$regel = `ipfw -a l`;
print "$regel\n";
while($regel =~ /(\d+)\s+(\d+)\s+(\d+).+[isp|gif]0/g){
#print "$1, $2, $3\n";
$data[$1] = $3;
}
`rrdtool update /root/traffic/totaal.rrd N:$data[100]:$data[200]`;
`rrdtool update /root/traffic/http.rrd N:$data[300]:$data[400]:$data[500]:$data[600]`;
`rrdtool update /root/traffic/smtp.rrd N:$data[700]:$data[800]:0:0`;
`rrdtool update /root/traffic/pop3.rrd N:$data[1100]:$data[1200]:0:0`;
`rrdtool update /root/traffic/dns.rrd N:$data[1500]:$data[1600]:0:0`;
`rrdtool update /root/traffic/ftp.rrd N:$data[1900]:$data[2000]:0:0`;
`rrdtool update /root/traffic/msn.rrd N:$data[2700]:$data[2800]:0:0`; |