How can I read out the value of internal counter inside IPSet

3

1

I know there is an option named “counters” when creating an IP set with IPSet. However, I want to know how to read the value of the counters out, so as to know how many packets or how much data has been forwarded from or to each IP address in the set.

Shanker Wang

Posted 2015-08-05T09:15:33.427

Reputation: 31

Answers

1

The quickest way is to just dump the ipset and look for the values. If you want it without dumping it, you'll probably want to write some C using the libipset API.

root@host # ipset save |grep  -e 'packets [1-9]'
add ganeti-v4 1.2.3.4 timeout 85663 packets 26 bytes 5876 comment "basedata: @1475359261 /etc/firewall.d/functions/ipset"
add ganeti-v4 1.2.3.5 timeout 85663 packets 30 bytes 6780 comment "basedata: @1475359261 /etc/firewall.d/functions/ipset"
add drbd-v4 4.5.6.7 timeout 85663 packets 4 bytes 240 comment "basedata: @1475359261 /etc/firewall.d/functions/ipset"

robbat2

Posted 2015-08-05T09:15:33.427

Reputation: 821