How to do speedtest with available package?

Hi, I ever made script to do speedtest and use the result to config SQM bandwidth automatically. Link here Help to make sh script for adjust SQM automaticaly
Now I want apply this to other router which have low flash & ram
the router is MR3220 V1 with AndyX custom openwrt. link custom rom here Minimum/Lite Firmware for TPLINK-MR1XU-MR3XXX-WA7XX-WA8XX-WA901ND-WA7X10N-WR7XXN-WR8XXN-WR9XXND-WR1041N & NETGEAR-WNR612-WNR1000-WNR2000-WPN824N (4M Flash ONLY)

My Goal is : create script to get speedtest result with available package, after i can get my download & upload speed. after i can get it, i can process the result same as my autoSQM script

this is available package

[                  dirname            hwclock            ln                 nice               sed                ubusd
[[                 dmesg              id                 lock               nlbw               seq                uci
ash                dnsmasq            ifconfig           logd               nlbwmon            sh                 uclient-fetch
askfirst           dropbear           ifdown             logger             nslookup           sha256sum          udevtrigger
awk                dropbearkey        ifstatus           login              ntpd               signify            udhcpc
basename           du                 ifup               logread            ntpd-hotplug       sleep              uhttpd
board_detect       echo               init               ls                 passwd             sort               umount
brctl              egrep              insmod             lsmod              pgrep              ssh                uname
bunzip2            env                ip                 lua                pidof              start-stop-daemon  uniq
busybox            etherwake          ip6tables          luci-bwc           ping               strings            upgraded
bzcat              expr               ip6tables-restore  luci-reload        ping6              swconfig           uptime
cat                false              ip6tables-save     md5sum             pivot_root         switch_root        urandom_seed
chgrp              fgrep              miniupnpd          poweroff           sync               usign
chmod              find               iptables           mkdir              pppd               sysctl             validate_data
chown              firstboot          iptables-restore   mkfifo             printf             sysupgrade         vi
chroot             free               iptables-save      mknod              procd              tail               wc
clear              fsync              iw                 mkswap             ps                 tar                wget
cmp                fw3                iwinfo             mktemp             pwd                tc                 which
config_generate    fwtool             jffs2mark          modinfo            readlink           tee                wifi
cp                 getrandom          jffs2reset         modprobe           reboot             test     
crond              grep               jshn               mount              reload_config      time               wpa_supplicant
crontab            gunzip             jsonfilter         mount_root         reset              top                wpad
cut                gzip               kill               mtd                rm                 touch              xargs
date               halt               killall            mv                 rmdir              tr                 xtables-multi
dbclient           head               kmodloader         nc                 rmmod              traceroute         yes
dd                 hexdump            ldd                netifd             route              traceroute6        zcat
devstatus          hostapd               netmsg             rpcd               true
df                 hotplug-call       less               netstat            scp                ubus

home someone can help share their knowledge for my plan

You can use iPerf3 to measure speed through your router. However, you probably won't get very good results when you test on the router itself -- the SoCs in most consumer routers are not powerful enough to be able to process packets (as an endpoint) at line rate... they are designed to route packets rapidly, but they cannot generate or terminate them fast enough to provide useful data.

That being said, you are not running an official build of OpenWrt, so I don't know if the iperf3 package is available for your build. You can either switch over to an official build, or request help from the AndyX community.

iperf3 is not available
i already post my packages list above

i was thinking to use scp to test download test.but i need use method to measure average speed when doing scp use packages above.
i have no idea To do it :sweat_smile:

if you have the opkg package manager, you may be able to install it.

I will repeat that you need to keep in mind that you are not going to get meaningful speed test results when running on the router itself, unless your connection speed is indeed relatively slow.

Finally, you should direct further questions to the appropriate forum (not here) since you are not using an official OpenWrt release. Or change to OpenWrt official.

Conceptually simple, use wget to download a file of known size from a known site and just measure the time this takes. Slightly trickier for upload, as only few sites will accept anonymous file uploads, and wget does not handle uploads at all. FTP might work. But I concurr with @psherman many router's do not have the oomph to perform Speedtest termination in addition to their normal duty.

Check out the speedtest-cli python script.

Also, I thought this was already a buildable package. My buildbox is in pieces at the moment, but I am almost sure it's there.. do a search (/) in menuconfig for speedtest

i tried use wget and wget from this build not even show speed currently measure download speed only is enough for me to build auto sqm

i still can find out how to measure wget download speed while running with available package from this build
need script expert to help hehe

I can't install any package anymore because this build no opkg

I can't install any packages anymore
no opkg
for my other router, i already succeeded create auto SQM script with netperf package.and it work so good

If you have python already installed, just get the .py file directly

If you don't have python installed on that router, and you can't add packages, there really isn't much left you're going to be able to do for quantifiable data.

unfortunately no python too sir
actually i wanna mimic real time traffic from luci

if i can findout how to get the data from ssh, i can use the data from specific tim while doing wget to measure average speed and use it as value for my auto SQM script :slight_smile:

Ah, see, that is a different question than you asked! :wink: Those values are available on luCi, so they have to be somewhere on-device. The real question you need to ask is, WHERE are those values kept.

Someone will be able to help with that, I'm not sure where it would be. Check your /tmp directory, as most of the sensor and luci data is stored there since it doesn't need to be saved anyway.

actually if someone give other method with current packages to measure realtime traffic is okay
that just sample, and i still cant find out how to get realtime traffic from terminal haha

No, i understand.

Check out /www/luci-static/resources/view/status/bandwidth.js, as that is the page luci is using, it seems. Maybe it'll give you an idea how it pulls it, and if you might be able to parse it.

If you really want to go basics, could you script out just checking the RX/TX bytes change from ifconfig over x duration?

From my WAN port

          RX packets:3241032 errors:0 dropped:0 overruns:0 frame:0
          TX packets:734683 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4189222576 (3.9 GiB)  TX bytes:113968899 (108.6 MiB)

You've got near realtime (loop it on a 5 second sleep, average it over 60 seconds, divide by 60?) data bandwith.

So.. Check this out..

#!/bin/sh /etc/rc.common
while true; do
   RX_1=`ifconfig eth0 | grep "RX bytes" | cut -f 2 -d : | cut -f 1 -d "("`
   TX_1=`ifconfig eth0 | grep "TX bytes" | cut -f 3 -d : | cut -f 1 -d "("`
   sleep 6
   RX_2=`ifconfig eth0 | grep "RX bytes" | cut -f 2 -d : | cut -f 1 -d "("`
   TX_2=`ifconfig eth0 | grep "TX bytes" | cut -f 3 -d : | cut -f 1 -d "("`

   RX_3=$(($RX_2 - $RX_1))
   RX_BYTES=$(($RX_3 * 10 / 60))
   RX_MBITS=$(($RX_BYTES / 125000))

   TX_3=$(($TX_2 - $TX_1))
   TX_BYTES=$(($TX_3 * 10 / 60))
   TX_MBITS=$(($TX_BYTES / 125000))

   echo "Averages bytes difference: download - $RX_BYTES bytes, upload - $TX_BYTES bytes"
   echo "Average MBits/sec: download - $RX_MBITS, upload - $TX_MBITS"


The output. I ran a speedtest while running it.

root@Shield:/etc# sh
Averages bytes difference: download - 146871 bytes, upload - 4383 bytes
Average MBits/sec: download - 1, upload - 0
Averages bytes difference: download - 30627041 bytes, upload - 277142 bytes
Average MBits/sec: download - 245, upload - 2
Averages bytes difference: download - 3684007 bytes, upload - 1498893 bytes
Average MBits/sec: download - 29, upload - 11
Averages bytes difference: download - 45446 bytes, upload - 1541054 bytes
Average MBits/sec: download - 0, upload - 12
1 Like

will try this one
if it success ill share my auto SQM with minimalist packages :smiley:

i did test, and the result is amazing, ill my company vps to do SCP download and upload for speedtest :smiley:

Averages bytes difference: download - 249455 bytes, upload - 16086 bytes
Average MBits/sec: download - 1, upload - 0
Averages bytes difference: download - 424971 bytes, upload - 21141 bytes
Average MBits/sec: download - 3, upload - 0
Averages bytes difference: download - 4444581 bytes, upload - 178094 bytes
Average MBits/sec: download - 35, upload - 1
Averages bytes difference: download - 7728443 bytes, upload - 289004 bytes
Average MBits/sec: download - 61, upload - 2
Averages bytes difference: download - 5934448 bytes, upload - 991635 bytes
Average MBits/sec: download - 47, upload - 7
Averages bytes difference: download - 310581 bytes, upload - 5458217 bytes
Average MBits/sec: download - 2, upload - 43
Averages bytes difference: download - 327623 bytes, upload - 5846915 bytes
Average MBits/sec: download - 2, upload - 46
Averages bytes difference: download - 253500 bytes, upload - 887443 bytes
Average MBits/sec: download - 2, upload - 7
Averages bytes difference: download - 575560 bytes, upload - 26139 bytes
Average MBits/sec: download - 4, upload - 0
1 Like

hi @Grommish, i got issue to kill the sh script after download test is done
this is my script

sh &
wget -O /dev/null
APP_PID=$(pgrep -f
echo $APP_PID
# && kill -9 $APP_PID
#echo "Kill PID"
#sleep 1
kill -9 $APP_PID

after wget finish i want to kill (contain ur script) to stop the measure, but my script above cant kill the process
alreayd try use killall, but always got output killall: no process killed
i already add ur script to write the result in file

Try this one. It will default to 5 iterations, but you can supply a number of rounds to go before it quits..

usage: ./ <# of rounds>
#!/bin/sh /etc/rc.common
# usage: ./ <# of rounds>
# Defaults to 5 rounds
if [ -z $1 ]

while [ $a -le $b ]; do
   RX_1=`ifconfig eth0 | grep "RX bytes" | cut -f 2 -d : | cut -f 1 -d "("`
   TX_1=`ifconfig eth0 | grep "TX bytes" | cut -f 3 -d : | cut -f 1 -d "("`
   sleep 6
   RX_2=`ifconfig eth0 | grep "RX bytes" | cut -f 2 -d : | cut -f 1 -d "("`
   TX_2=`ifconfig eth0 | grep "TX bytes" | cut -f 3 -d : | cut -f 1 -d "("`

   RX_3=$(($RX_2 - $RX_1))
   RX_BYTES=$(($RX_3 * 10 / 60))
   RX_MBITS=$(($RX_BYTES / 125000))

   TX_3=$(($TX_2 - $TX_1))
   TX_BYTES=$(($TX_3 * 10 / 60))
   TX_MBITS=$(($TX_BYTES / 125000))

   echo "Average bytes difference ($a): download - $RX_BYTES bytes, upload - $TX_BYTES bytes"
   echo "Average MBits/sec ($a): download - $RX_MBITS, upload - $TX_MBITS"
   a=$((a + 1))
1 Like