Topic/Connection statistic measurements

@forouher FYI

This PR replaces #383. I have:
* squashed your commits
* cleaned up some more code
* and fixed a compilation error with the unit tests in order to run CI

Please provide further patches against this branch.