1
#!/usr/local/bin/python
10
# process syslog output from flow-capture and flow-fanout into a rrd
11
# Requires flow-tools-0.66 or above.
13
# -p allows configuration of the path to the rrd file
15
# rrd's have a DS of flows, pkts, and lost. When processing the output of
16
# flow-fanout an additional send_nobufs DS is used.
22
opts, args = getopt.getopt(sys.argv[1:], 'p:')
29
line = sys.stdin.readline()
35
if (len(fields) < 6) or (fields[5] != 'STAT:'):
36
line = sys.stdin.readline()
39
if fields[4][5:11] == 'fanout' :
41
elif fields[4][5:12] == 'capture' :
44
raise ValueError, "Expecting flow-capture or flow-fanout logs, got %s" %\
50
type, value = f.split('=')
57
rrdFile = '%s/%s.%s.%s.%s.%s.rrd' %\
58
(rrdPath, name, fields[3],tv['src_ip'],tv['dst_ip'],tv['d_ver'])
60
update = '%s:%s:%s:%s' % (tv['now'],tv['flows'],tv['pkts'],tv['lost'])
63
update = '%s:%s' % (update, tv['send_nobufs'])
65
if not testFile.get(rrdFile, 0):
67
if not os.access(rrdFile, os.F_OK) :
69
print 'Creating RRD ', rrdFile
71
if name == 'capture' :
73
# 7 days of 5 minute averages (no averaging)
74
# 365 days of 1 day averages
75
rrdtool.create(rrdFile, '--start', str(int(tv['now']) - 300),
76
'DS:flows:COUNTER:600:U:U',
77
'DS:pkts:COUNTER:600:U:U',
78
'DS:lost:COUNTER:600:U:U',
79
'RRA:AVERAGE:0.5:1:2016',
80
'RRA:AVERAGE:0.5:288:365')
83
elif (name == 'fanout') :
85
rrdtool.create(rrdFile, '--start', str(int(tv['now']) - 300),
86
'DS:flows:COUNTER:600:U:U',
87
'DS:pkts:COUNTER:600:U:U',
88
'DS:lost:COUNTER:600:U:U',
89
'DS:nobufs:COUNTER:600:U:U',
90
'RRA:AVERAGE:0.5:1:2016',
91
'RRA:AVERAGE:0.5:288:365')
94
rrdtool.update(rrdFile, update)
96
line = sys.stdin.readline()