~ubuntu-branches/ubuntu/dapper/flow-tools/dapper

« back to all changes in this revision

Viewing changes to bin/flow-log2rrd

  • Committer: Bazaar Package Importer
  • Author(s): Radu Spineanu
  • Date: 2005-06-02 20:12:57 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050602201257-jv0qdk3hjhpdf04b
Tags: 1:0.68-2
Fixed a bashism in init script (closes: #311568)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/python
 
2
 
 
3
import getopt
 
4
import os
 
5
import rrdtool
 
6
import sys
 
7
import string
 
8
 
 
9
#
 
10
# process syslog output from flow-capture and flow-fanout into a rrd
 
11
# Requires flow-tools-0.66 or above.
 
12
#
 
13
# -p allows configuration of the path to the rrd file
 
14
#
 
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.
 
17
#
 
18
 
 
19
# default to cwd
 
20
rrdPath = '.'
 
21
 
 
22
opts, args = getopt.getopt(sys.argv[1:], 'p:')
 
23
 
 
24
for o, v in opts:
 
25
  if o == '-p' :
 
26
    rrdPath = v;
 
27
 
 
28
testFile = {}
 
29
line = sys.stdin.readline()
 
30
 
 
31
while line :
 
32
 
 
33
  fields = line.split()
 
34
 
 
35
  if (len(fields) < 6) or (fields[5] != 'STAT:'):
 
36
    line = sys.stdin.readline()
 
37
    continue
 
38
 
 
39
  if fields[4][5:11] == 'fanout' :
 
40
    name='fanout'
 
41
  elif fields[4][5:12] == 'capture' :
 
42
    name='capture'
 
43
  else :
 
44
    raise ValueError, "Expecting flow-capture or flow-fanout logs, got %s" %\
 
45
      fields[4]
 
46
 
 
47
  tv = {}
 
48
  for f in fields :
 
49
    try :
 
50
      type, value = f.split('=')
 
51
    except ValueError :
 
52
      continue
 
53
 
 
54
    tv[type] = value
 
55
 
 
56
 
 
57
  rrdFile = '%s/%s.%s.%s.%s.%s.rrd' %\
 
58
    (rrdPath, name, fields[3],tv['src_ip'],tv['dst_ip'],tv['d_ver'])
 
59
 
 
60
  update = '%s:%s:%s:%s' % (tv['now'],tv['flows'],tv['pkts'],tv['lost'])
 
61
 
 
62
  if name == 'fanout' :
 
63
    update = '%s:%s' % (update, tv['send_nobufs'])
 
64
 
 
65
  if not testFile.get(rrdFile, 0):
 
66
 
 
67
    if not os.access(rrdFile, os.F_OK) :
 
68
 
 
69
      print 'Creating RRD ', rrdFile
 
70
 
 
71
      if name == 'capture' :
 
72
 
 
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')
 
81
        testFile[rrdFile] = 1
 
82
 
 
83
      elif (name == 'fanout') :
 
84
 
 
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')
 
92
        testFile[rrdFile] = 1
 
93
 
 
94
  rrdtool.update(rrdFile, update)
 
95
 
 
96
  line = sys.stdin.readline()
 
97