[SailfishDevel] network statistics for sailfish

Thomas Perl th.perl at gmail.com
Mon Dec 16 22:40:10 UTC 2013


Hey,

2013/12/16 Martin Grimme <martin.grimme at gmail.com>:
> 2013/12/16, W. Dobbe <winfried.dobbe at xmsnet.nl>:
>> Probably that will be the end conclusion, but Android is also Linux, so how
>> do the Android network monitor apps get their information? Does the android
>> stack/Dalvik give extra hooks for network inspection ?
>
> Android is not Linux. Android is as much Linux as iOS is BSD.
> Android runs on top of a Linux kernel, but that's all Android and
> GNU/Linux have in common.
> Network inspection is probably exposed by the Android Java API.

In Android, every application has its own UID, so the "bandwidth per
app" problem can be reduced to "bandwidth per user" in that case. If
you look around the Android sources, there's a way to access these
stats:

https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.2/core/java/android/net/NetworkStats.java

And this is how the stats are collected:

https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.2/services/java/com/android/server/net/NetworkStatsCollection.java
https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.2/services/java/com/android/server/net/NetworkStatsRecorder.java
https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.2/services/java/com/android/server/net/NetworkStatsService.java

With that said, it's definitely possible with some motivation to do
per-process bandwidth tracking, we did something like this for a Uni
course some years ago:

http://thp.io/2010/bwmon/

This uses the "ip_conntrack" kernel module or - with more recent
kernels - conntrack-tools:

http://conntrack-tools.netfilter.org/

There's even some documentation on how to use the bwmon utility:

http://thp.io/2010/bwmon/manual.html

If you plan on using that for the mobile device use case, think about
rewriting the thing in C/C++ instead of Python and make it less
resource-hungry by reducing wake-ups. As Harbour apps are now prefixed
with "harbour-" and have strict requirements for .desktop and icon
file naming, it should be easy to make a system that calculates
per-app bandwidth usage and shows the icon of the app and the name of
the app without too much work.


HTH :)
Thomas


More information about the Devel mailing list