2 # -*- coding: utf-8 -*-
4 from __future__
import absolute_import
8 from optparse
import OptionParser
10 sys
.path
.insert(0, os
.path
.dirname(__file__
) or '.')
12 if __name__
== '__main__':
13 from bwmon
import monitor
15 parser
= OptionParser()
16 parser
.add_option('--include', dest
='include_filter', type='string', action
='append', help='include only processes that match the given regex')
17 parser
.add_option('--exclude', dest
='exclude_filter', type='string', action
='append', help='exclude processes that match the given regex')
18 parser
.add_option('--bandwidth', dest
='bandwidth', action
='store_true', default
=False, help='print bandwidth instead of traffic')
19 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')
20 parser
.add_option('--ignore-local', dest
='ignorelocal', action
='store_true', default
=False, help='ignore local traffic')
22 (options
, args
) = parser
.parse_args()
24 m
= monitor
.Monitor(options
.lookback
, options
.ignorelocal
)
25 m
.set_filter(options
.include_filter
, options
.exclude_filter
)
27 m
.loop(monitor
.BANDWIDTH
)
29 m
.loop(monitor
.TRAFFIC
)