Xposed-NetworkSpeedIndicator icon indicating copy to clipboard operation
Xposed-NetworkSpeedIndicator copied to clipboard

Can it ignores the lo traffics?

Open wzhy90 opened this issue 10 years ago • 24 comments

When I use ShadowSocks, it will also collect the lo interface's traffic. Can the software ignores the lo interface?

wzhy90 avatar Jan 03 '15 06:01 wzhy90

Like this, only the wlan0 interface is the valid internet traffic

root@D6503:/ # ifconfig                                                        
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:393592 errors:0 dropped:0 overruns:0 frame:0
          TX packets:393592 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:430081434 (410.1 MiB)  TX bytes:430081434 (410.1 MiB)

wlan0     Link encap:Ethernet  HWaddr 44:D4:E0:82:8C:87  
          inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::46d4:e0ff:fe82:8c87/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:150874 errors:0 dropped:485 overruns:0 frame:0
          TX packets:114157 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:211721446 (201.9 MiB)  TX bytes:8636489 (8.2 MiB)

wzhy90 avatar Jan 03 '15 06:01 wzhy90

What do you mean by ShadowSocks? Anyway I can't find a way to gather statistics for a specific interface. If you can find one, please pitch it forward!! :smile:

ADTC avatar Jan 03 '15 14:01 ADTC

shadowsocks will use the lo interface to forwarding network traffic, and this software will collect it too.

wzhy90 avatar Jan 03 '15 15:01 wzhy90

This is a common problem when using any app or function that uses the lo interface. Not related to ShadowSocks itself. As said, I haven't found a way to filter out the loopback interface.

ADTC avatar Jan 03 '15 16:01 ADTC

That's so sad...

wzhy90 avatar Jan 03 '15 23:01 wzhy90

maybe look at this , it's ture speed. https://play.google.com/store/apps/details?id=com.internet.speed.meter.lite

codexss avatar Feb 28 '15 13:02 codexss

#93 is duplicate of this.

It may be possible to exclude the lo interface by reading the actual stat files:

/sys/class/net/lo/statistics/tx_bytes
/sys/class/net/lo/statistics/rx_bytes

Any idea how to actually read and parse these files and read them in Java? But I think it might be horribly inefficient to do this, maybe not even possible at all, since TrafficStats itself uses native C to read the statistics.

See http://agolovatyuk.blogspot.com/ncr/2012/04/android-traffic-statistics-inside.html

ADTC avatar Feb 28 '15 13:02 ADTC

So I tried the above, and it seems to work... in a way. It seems to exclude the lo traffic, but in my device there was only 31597 bytes lo traffic both ways since boot and it never changed after that. I don't see any obvious inefficiency, but we can strike out the impossibility.

See commit below for actual code doing this. Comments and suggestions for a better way to do this most welcome.

Is there any simple app that I can use to jack up the lo traffic and see if it makes any difference? Or any volunteers to test?

ADTC avatar Feb 28 '15 15:02 ADTC

U can send me a apk file ,i will test it.

codexss avatar Mar 01 '15 01:03 codexss

@codexss Here it is

When testing, enable logging for a while when you increase the lo traffic. Then send the generated log file. You can disable logging after that.

ADTC avatar Mar 01 '15 07:03 ADTC

It seems work! 1.0b2-issus-86

wzhy90 avatar Mar 01 '15 08:03 wzhy90

screenshot_2015-03-01-16-24-35 It's seems not, here is log http://paste.ubuntu.com/10483351/

codexss avatar Mar 01 '15 08:03 codexss

As per the log, it is filtering out the increasing lo traffic, so the original intention to ignore the lo traffic is working.

D/2015-03-01 16:30:17/0 total: 16440969, lo: 13705297
D/2015-03-01 16:30:17/1 total: 39329404, lo: 13705297
D/2015-03-01 16:30:17/2725311,2735672;25458843,25624107;208219,209225;10299,164278
D/2015-03-01 16:30:18/0 total: 16444520, lo: 13707672
D/2015-03-01 16:30:18/1 total: 39332358, lo: 13707672
D/2015-03-01 16:30:18/2735672,2736848;25624107,25624686;209225,210241;1157,569
D/2015-03-01 16:30:19/0 total: 16453655, lo: 13711527
D/2015-03-01 16:30:19/1 total: 39338466, lo: 13711527
D/2015-03-01 16:30:19/2736848,2742128;25624686,25626939;210241,211252;5222,2228

Can you say why you think it's not working?

Btw, the screenshot is just a download of the speed test app. It's not an actual speed test.

ADTC avatar Mar 01 '15 09:03 ADTC

Contrast that with another app, I look at it over a period of time, thanks to the developer

codexss avatar Mar 01 '15 09:03 codexss

I put the upload and download figures in some charts and I can tell that that the lo traffic is being excluded correctly. It is still accounting for all other network interfaces that are active.

This is the upload chart. The blue line is the total upload bytes (since boot) and the red one is the lo traffic (since boot).

As you can see, they are pretty close together and most of the total traffic is lo traffic, which is filtered out (and hence your upload speed will not dramatically increase due to loopback when you're downloading something).

Upload chart

This is the download chart. Here you can see that lo traffic is only about one-third of the total traffic. The rest comes from whatever download you were doing during the time of logging.

Download chart

To me this is correct and how it should be. Evidently, your screenshot shows that this app's upload speed report is just 34 KB/s while the download speed is 1.4 MB/s (because you're downloading the speedtest app for installation).

I'm not sure what app is showing 697 KB/s and how it came up with that figure. :smile:

ADTC avatar Mar 01 '15 09:03 ADTC

It's still have problem at shadowsocks vpn mode ,but it's works at shadowsocks nat mode.

codexss avatar Mar 01 '15 11:03 codexss

What does it do in VPN mode? I suspect it creates a new network interface for the VPN and this traffic is included, while the native mode uses the loopback lo interface. I think this is the best that can be done by me. We need someone more knowledgeable to provide hints about this, but I'll include this in the next release.

ADTC avatar Mar 01 '15 11:03 ADTC

I may have to change the approach to only counting a limited set of valid interfaces (such as ethernet and wifi) instead of excluding a non-exhaustive set of invalid interfaces (such as proxy loopback lo and tunnel devices).

Would that work?

ADTC avatar Mar 02 '15 12:03 ADTC

Can it list the interfaces and let user to choose?

dantmnf avatar Apr 21 '15 04:04 dantmnf

Vote for @dantmnf. When this change will released?

CzBiX avatar Jul 22 '15 17:07 CzBiX

image

left is the output of ip a when shadowsocks enabled, and right is when shadowsocks disabled. On my device, it add a interface named "tun0".

nagae-memooff avatar Nov 20 '15 08:11 nagae-memooff

@nagae-memooff tun0 is on not rooted android 5.0+ devices when using vpn mode. If you are using 4.4 or lower or using shadowsocks with root permission, it will use iptables to forward the network transport.

wzhy90 avatar Nov 21 '15 14:11 wzhy90

@wzhy90
my device is already rooted. on 5.0+ devices, shadowsocks will use VPN mode by default, and the NAT mode is hidden and deprecated.

nagae-memooff avatar Nov 21 '15 14:11 nagae-memooff

SO, if we want a more accurate net speed rate, not only lo but also tun0 should be excluded, I think.

nagae-memooff avatar Nov 21 '15 14:11 nagae-memooff