@@ -308,6 +308,7 @@ command:
308308
309309Counters
310310--------
311+
311312You can query rule and chain counters, e.g.:
312313
313314 >>> import iptc
@@ -317,36 +318,40 @@ You can query rule and chain counters, e.g.:
317318 >>> (packets, bytes) = rule.get_counters()
318319 >>> print packets, bytes
319320
320- However, the counters are only refreshed when the underlying low-level iptables connection is refreshed in ` Table ` via ` table.refresh() ` . For example:
321-
322- import time, sys
323- import iptc
324- table = iptc.Table(iptc.Table.FILTER)
325- chain = iptc.Chain(table, 'OUTPUT')
326- for rule in chain.rules:
327- (packets, bytes) = rule.get_counters()
328- print packets, bytes
329- print "Please send some traffic"
330- sys.stdout.flush()
331- time.sleep(3)
332- for rule in chain.rules:
333- # Here you will get back the same counter values as above
334- (packets, bytes) = rule.get_counters()
335- print packets, bytes
336-
337- This will show you the same counter values even if there was traffic hitting your rules. You have to refresh your table to get update your counters:
338-
339- import time, sys
340- import iptc
341- table = iptc.Table(iptc.Table.FILTER)
342- chain = iptc.Chain(table, 'OUTPUT')
343- for rule in chain.rules:
344- (packets, bytes) = rule.get_counters()
345- print packets, bytes
346- print "Please send some traffic"
347- sys.stdout.flush()
348- time.sleep(3)
349- table.refresh() # Here: refresh table to update rule counters
350- for rule in chain.rules:
351- (packets, bytes) = rule.get_counters()
352- print packets, bytes
321+ However, the counters are only refreshed when the underlying low-level
322+ iptables connection is refreshed in ` Table ` via ` table.refresh() ` . For
323+ example:
324+
325+ >>> import time, sys
326+ >>> import iptc
327+ >>> table = iptc.Table(iptc.Table.FILTER)
328+ >>> chain = iptc.Chain(table, 'OUTPUT')
329+ >>> for rule in chain.rules:
330+ >>> (packets, bytes) = rule.get_counters()
331+ >>> print packets, bytes
332+ >>> print "Please send some traffic"
333+ >>> sys.stdout.flush()
334+ >>> time.sleep(3)
335+ >>> for rule in chain.rules:
336+ >>> # Here you will get back the same counter values as above
337+ >>> (packets, bytes) = rule.get_counters()
338+ >>> print packets, bytes
339+
340+ This will show you the same counter values even if there was traffic
341+ hitting your rules. You have to refresh your table to get update your
342+ counters:
343+
344+ >>> import time, sys
345+ >>> import iptc
346+ >>> table = iptc.Table(iptc.Table.FILTER)
347+ >>> chain = iptc.Chain(table, 'OUTPUT')
348+ >>> for rule in chain.rules:
349+ >>> (packets, bytes) = rule.get_counters()
350+ >>> print packets, bytes
351+ >>> print "Please send some traffic"
352+ >>> sys.stdout.flush()
353+ >>> time.sleep(3)
354+ >>> table.refresh() # Here: refresh table to update rule counters
355+ >>> for rule in chain.rules:
356+ >>> (packets, bytes) = rule.get_counters()
357+ >>> print packets, bytes
0 commit comments