On 2021/04/01 12:42, Anton Rieger wrote:
On Thu, Apr 01, 2021 at 10:08:32AM +0200, Frank Wunderlich wrote:
made a little python-script (not yet with error-handling) to read out
the bytes:
import os
import json
def getCounter(countername):
stream = os.popen('nft list counter filter '+countername+' -j')
output = stream.read()
#print(output)
j=json.loads(output)
return j["nftables"][0]["counter"]["bytes"]
print(getCounter("voip1"),"bytes")
print(getCounter("voip2"),"bytes")
Here's above using the nftables python module:
```
from nftables import Nftables
from nftables import json
def getCounter(countername, family='ip'):
nft = Nftables()
nft.set_json_output(True)
_, output, _ = nft.cmd(f"list counter {family} filter {countername}")
j = json.loads(output)
return j['nftables'][1]["counter"]["bytes"]
print(getCounter('voip1'), 'bytes')
print(getCounter('voip2'), 'bytes')
```
Greetings
Anton
Nice!
Anton & Frank W., is it OK with you if I include your examples in the
nftables wiki?
Thanks,
Frank M.