Bitcoin Forum

Bitcoin => BitcoinJ => Topic started by: jonas.schnelli on September 23, 2013, 12:08:27 PM



Title: bitcoinj network (low level) statistics
Post by: jonas.schnelli on September 23, 2013, 12:08:27 PM
Hi

I'd like to get some low level network statistics for all traffic done by bitcoinj.
Goal should be to count/cumulate total bytes in / bytes out as well as the current traffic bandwidth.

Is there already something implemented?
If not, where could i start implementing a such thing?

Thanks
---


Title: Re: bitcoinj network (low level) statistics
Post by: Mike Hearn on September 23, 2013, 02:22:42 PM
It's not implemented. Matt Corallo rewrote the networking layer, it's here:

https://code.google.com/r/bluemattme-bitcoinj/source/list?name=nonetty

His changes remove netty and replace it with a home grown framework. I'm slowly working through code review, but you could grab it and try it out to see how it looks. If it seems good then adding stats collection would be a nice improvement. Alternatively, adding hooks in the right place so stats collection can easily be plugged in would be even better.

In the current framework you can attach an onPreMessageReceived handler to get all inbound messages and calculate bytes used from that, but for outbound messages you'd need to modify the code itself.


Title: Re: bitcoinj network (low level) statistics
Post by: jonas.schnelli on September 24, 2013, 12:01:32 PM
Thanks.

Is there any plan when matt's changes (own framework) will be implemented?
(to decide where to implement)


Title: Re: bitcoinj network (low level) statistics
Post by: Mike Hearn on September 24, 2013, 12:50:40 PM
You can see his changes here:

https://code.google.com/r/hearn-bitcoinj/source/detail?r=63309f5706f1918ef5b5ec29e35d4bc7fb9abeca&name=nonetty

I did a review this morning. It's looking pretty reasonable, but isn't quite mergeable yet. Hopefully soon, once we get some real world testing and address my comments. I'm going to keep it rebased at any rate. So I'd suggest building on top of that branch.

I think the best way to implement it post-nonetty is modifying PeerSocketHandler to record stats in the receiveBytes and sendMessage calls. Then you could make PeerGroup accumulate the statistics.

It looks like it isn't possible to do that in an easily pluggable way because PeerGroup always directly instantiates Peer. We could introduce a PeerFactory type glue point and then API users could customize the Peer objects that are in use, but bandwidth stats might be generally useful for everyone.

What is it you want to do with the data?


Title: Re: bitcoinj network (low level) statistics
Post by: jonas.schnelli on September 24, 2013, 01:18:18 PM
Sounds good. I first need to check the sources to get a plan about it.

I developing a tiny mac app with goals...
... very easy to use (dumb end user capable)
... low mem / cpu footprint
... take at less UI space as possible (status bar).

Simple screenshot of early dev status:
https://i.imgur.com/IT25qSc.jpg

I would like to integrate a bandwidth statistics as well as a small network graph into the app. So user can prove what goes over the network. And this would also be a psychological sign for the user, that the wallet/bitcoin network is alive.
More and more user are also connected over 3G/4G over iPhone/Android tethering and might be concerned about bandwidth usage.

--
</jonas>


Title: Re: bitcoinj network (low level) statistics
Post by: Mike Hearn on September 24, 2013, 03:36:04 PM
Android offers data usage monitoring at the OS level. Most clients just show number of connected peers. But sure, you could show such data if you wanted to.