Update information on conntrack accounting
authorThomas Perl <m@thp.io>
Sat, 3 Nov 2012 12:11:33 +0000 (3 13:11 +0100)
committerThomas Perl <m@thp.io>
Sat, 3 Nov 2012 12:11:33 +0000 (3 13:11 +0100)
README
bwmon/monitor.py

diff --git a/README b/README
index 5ddbf52..9fc6441 100644 (file)
--- a/README
+++ b/README
    a replacement, bwmon now supports the "conntrack" command-line
    utility from the "conntrack-utils" package.
 
-   If you get "KeyError: 'bytes'", this is a known problem, see:
-   http://marc.info/?l=netfilter&m=135194333402321&w=2
+   Make sure to run this command to enable accounting for conntrack
+   (otherwise you might get a "KeyError: 'bytes'" traceback):
+
+       sysctl -w net.netfilter.nf_conntrack_acct=1
+
+   Sometimes you have to wait a bit after setting this option to
+   make sure old connections are removed from conntrack's output.
+
+   Related netfilter mailing list thread:
+
+       http://marc.info/?t=135194346800001&r=1&w=2
 
 
  -- More information --
index ff9d08e..2cfd3a3 100644 (file)
@@ -155,10 +155,19 @@ class Monitor(object):
             for direction in ('in', 'out'):
                 k = keys[direction]
                 if k in self.conntrack:
-                    if key_in in self.last_conntrack:
-                        new_byte[direction] = int(self.conntrack[k]['bytes']) - int(self.last_conntrack[k]['bytes'])
-                    else:
-                        new_byte[direction] = int(self.conntrack[k]['bytes'])
+                    try:
+                        if key_in in self.last_conntrack:
+                            diff = (int(self.conntrack[k]['bytes']) -
+                                    int(self.last_conntrack[k]['bytes']))
+                        else:
+                            diff = int(self.conntrack[k]['bytes'])
+                    except KeyError:
+                        print >>sys.stderr, ("WARNING: No 'bytes' field in output (use '"
+                                "sysctl -w net.netfilter.nf_conntrack_acct=1"
+                                "' to enable accounting.")
+                        sys.exit(1)
+
+                    new_byte[direction] = diff
 
             current_in, current_out = entries[process['cmd']]
             new_in, new_out = (new_byte['in'], new_byte['out'])