svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
957 stars 247 forks source link

TCP flow statistics for other network namespace #707

Open christian-2 opened 4 years ago

christian-2 commented 4 years ago

So I know how to obtain e.g. links that reside in another network namespace (with NetNS.get_links()), and I also know how to obtain TCP flow statistics for the default network namespace (with DiagSocket.get_sock_stats()).

Does pyroute2 currently allow obtaining TCP flow statistics for flows whose source or destination links reside in non-default (named) network namespaces, and if so how? Great package BTW.

I have e.g. tried calling DiagSocket.get_sock_stats() from a subprocess after switching its netns but that did not seem to work:

def stat():
  nonlocal pid
  pyroute2.netns.setns('/proc/{}/ns/net'.format(pid))
  with pyroute2.DiagSocket() as ds:
    ds.bind()
    sstats = ds.get_sock_stats(...)
    # ...

process = multiprocessing.Process(target=stat)
process.start()
svinota commented 4 years ago

Let me investigate a bit. Never tried yet, so we'll see.