Kiougar / luci-wrtbwmon

Bandwidth tracker for OpenWRT that uses wrtbwmon
https://github.com/pyrovski/wrtbwmon
MIT License
327 stars 56 forks source link

Same client shown more than once #18

Open NaruZosa opened 6 years ago

NaruZosa commented 6 years ago

Firstly, thank you so much for the recent changes, they're absolutely wonderful!

I've run into a small problem though, I have the same device appearing twice on two occasions in the usage details.

Here's a link to a screenshot, the devices in question are Printer 1 and Printer 2 https://www.dropbox.com/s/0ttu4c1txn6m4p4/Duplicate%20Clients.png?dl=0

And here is my custom user file:

1c:1b:0d:e5:60:f1,Bradley
d8:6c:63:72:7a:62,Chromecast 2
f0:03:8c:1e:2f:09,Brian
94:de:80:23:6a:1c,Grandma
c0:ee:fb:df:65:51,Bradley OP3
d0:73:d5:03:3d:c0,Bradley Lifx
d8:49:2f:e0:eb:88,Printer 1
60:12:8b:91:ca:29,Printer 2
e8:61:7e:22:02:11,Jarrod PS4
00:08:74:24:a3:25,Bradley Server
1c:1b:0d:97:b8:a2,Jarrod??

Hovering over Printer 1 and Printer 2 in the usage details shows that both results for Printer 1 have the same mac address and both results for Printer 2 have the same mac address as well.

It looks like they changed IP addresses and now they're being recognised as new devices, even though their mac address is still the same.

Is there any way to fix this other than assigning them static IP addresses?

Also, offtopic, but would it be possible to have the 'Submit' and 'Reset' buttons on the 'User File' page replaced with 'Save & Apply', 'Save' and 'Reset' buttons like in the configuration page and elsewhere in LuCI?

Thanks a lot for all your hard work, it's really appreciated!

Kiougar commented 6 years ago

I'm glad you liked the changes!

Is there any way to fix this other than assigning them static IP addresses?

I can't think of a better way than assigning static addresses. Will look into it though and get back to you.

Also, offtopic, but would it be possible to have the 'Submit' and 'Reset' buttons on the 'User File' page replaced

I used the LuCI CBI SingleForm model which has these buttons by default. You can see that these same buttons appear in the page Network - Firewall - Custom (if I'm not mistaken). Although you might see different text for the Submit button depending on the version of LuCI. Save and apply does not apply here because we are simply saving to a file. The apply part only works on configuration changes that are only saved in memory and need to be committed by the apply action.

NaruZosa commented 6 years ago

Ah, okay. That makes sense.

Would it be possible to have it recognise new devices based on new mac addresses, rather than new IP addresses, or would that be too much work/out of your control?

brvphoenix commented 6 years ago

@BradleyDS2 I modified the readDB.awk of wrtbwmon , which makes it possible that the wrtbwmon creates the usage.db by the host's MAC. Perhaps it can sovle the issue.

https://drive.google.com/open?id=1LjZ_zyqe_7AafR9Dr_QNuzRHcjRrN9Bz

fakuivan commented 6 years ago

Data usage used to be calculated using only MAC addresses, but because of the implementation luci-wrtbmon ended up showing funny values, as seen in issue #7

brvphoenix commented 6 years ago

@fakuivan The issue you mentioned above is caused by the repeated MAC address in the file of usage.db and the patch had fixed the issue by recongising the client by considering the ip and MAC address at the same time.

However, I modified the codes of the wrtbwmon rather than the luci-wrtbwmon so that it caculates the traffic data only based on the MAC address. By my modified codes, the same MAC address will not appear more than onces in the file of usage.db, and one MAC address correspond to a unique client. Therefore, the issue #7 could not occur.

I modified the wrtbwmon because the wrtbwmon caculate the traffic data by the ip address only. It may recongise the incorrected client if the ip has changed for a client and another client just get the same old ip address of the former.

If you are interested in this issue, you can just replace the /usr/sbin/readDB.awk by the file I offered above. I have tested it for some days and no bugs occured up to now.

ghost commented 6 years ago

@brvphoenix

Hello! I used your readDB.awk, it works as expected, but exactly until the appearance of a new device on the network. If its traffic is 0 bytes, the statistics in the browser through usage.htm disappears on all devices, only the headings of the columns Download, Upload, Total, etc. remain. When the device has traffic, even 1 byte, statistics appear again.

Also, I noticed in the usage.htm file the incorrect layout of the quotes and the absence of the Upload value on this device.

new Array("Sunny","00:00:04:f8:31:16","192.168.1.2",
12751.000000,1935,14686,"12-14-2017_14:28:06","01-01-2018_10:28:06"),

new Array("Andrew","00:08:82:ed:df:02","192.168.1.3",
1184.000000,873,2057,"12-14-2017_14:28:06","01-01-2018_10:12:09"),

new Array("John","00:12:aa:ba:17:04","192.168.1.4",
0.000000,0,01-01-2017_9:02:49,"01-01-2017_10:34:21",""),

What can you do about it?

ghost commented 6 years ago

It seems that the problem is solved. Added two "+" in the penultimate section in readDB.awk and began to display statistics for all devices even with their traffic of 0 bytes.

        else{
            bw[lb "/in"]   +=  arp_bw[ii "/in"]
            bw[lb "/out"]  +=  arp_bw[ii "/out"]
            firstDate[lb]  =  lastDate[lb] = arp_firstDate[ii]
        }
brvphoenix commented 6 years ago

@Gganazage You'd better to change the readDB.awk as the picture as follows. The disapperance of some data may be caused by the variables initialized by empty string. default