Data usage can be found in ifconfig
output for each interface. In the following example, it assumes rmnet_mhi0
is the name of the interface.
echo $(($(adb shell ifconfig rmnet_mhi0 | grep "RX bytes" | cut -d ":" -f 2|cut -d " " -f 1)/1024)) Mb
but this is since last reboot or last connection.
or: https://gist.github.com/Zibri/387f0bd0acf09f71384ce78dd45aa058
#!/bin/bash
# Get android network usage statistics from phone.
# by Zibri
function getUsage ()
{
rb=0;
tb=0;
for a in $(adb shell dumpsys netstats|grep "rb="|cut -d "=" -f 3|cut -d " " -f 1);
do
rb=$((rb+a/1024));
done;
rb=$((rb/2));
for a in $(adb shell dumpsys netstats|grep "rb="|cut -d "=" -f 5|cut -d " " -f 1);
do
tb=$((tb+a/1024));
done;
tb=$((tb/2));
echo RX: $rb Kb TX: $tb Kb
echo Total: $(((rb+tb)/1024)) Mb
};
getUsage
which gives you the same number you get in settings/data usage menu.
(in my case this is what I needed).