Update information on conntrack accounting
[bwmon.git] / runmonitor.py
blob67f98ea53b41337cbdd77d45bc224ee2f7e91bce
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # Copyright 2010 Thomas Perl and Stefan Kögl. All rights reserved.
6 # Developed for a practical course (Large-scaled distributed computing) at the
7 # University of Technology Vienna in the 2010 summer term.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
12 # 1. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright notice,
16 # this list of conditions and the following disclaimer in the documentation
17 # and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
22 # EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 from __future__ import absolute_import
33 import os
34 import sys
35 from optparse import OptionParser
37 sys.path.insert(0, os.path.dirname(__file__) or '.')
39 if __name__ == '__main__':
40 from bwmon import monitor
42 parser = OptionParser()
43 parser.add_option('--include', dest='include_filter', type='string', action='append', help='include only processes that match the given regex')
44 parser.add_option('--exclude', dest='exclude_filter', type='string', action='append', help='exclude processes that match the given regex')
45 parser.add_option('--bandwidth', dest='bandwidth', action='store_true', default=False, help='print bandwidth instead of traffic')
46 parser.add_option('--no-lookback', dest='lookback', action='store_false', default=True, help='don\'t try to measure traffic that was generated before the monitor has been started')
47 parser.add_option('--ignore-local', dest='ignorelocal', action='store_true', default=False, help='ignore local traffic')
49 (options, args) = parser.parse_args()
51 m = monitor.Monitor(options.lookback, options.ignorelocal)
52 m.set_filter(options.include_filter, options.exclude_filter)
53 if options.bandwidth:
54 m.loop(monitor.BANDWIDTH)
55 else:
56 m.loop(monitor.TRAFFIC)