iTranslated by AI
Regularly Monitoring Internet Connection Speed with Speedtest CLI
I was consulted by my apartment's management association regarding the internet connection environment (speed by time of day). I thought it would be more persuasive to speak based on quantitative data, so I used Speedtest CLI to collect data once per hour for 24 hours (24 data points). This article summarizes that process.
The execution environment for this article is macOS Big Sur. I used cron for periodic execution, but if you are on Windows, you can likely achieve the same thing using Task Scheduler.
Downloading and Running Speedtest CLI
Download the tool from the Speedtest CLI website. While it seems available via Homebrew (brew), I only planned for short-term use, so I downloaded the file from "Download for macOS". I then extracted the downloaded ookla-speedtest-1.0.0-macosx.tgz file.
Moving to the extracted directory in the terminal, you can see the following files are included:
% cd ookla-speedtest-1.0.0-macosx
% ls -la
-rwxr-xr-x@ 1 yourusername staff 1387140 10 29 2019 speedtest
-rw-r--r--@ 1 yourusername staff 12377 10 29 2019 speedtest.5
-rw-r--r--@ 1 yourusername staff 11488 10 29 2019 speedtest.md
Run ./speedtest -h (to display help). The first time you run it, macOS will show an unverified developer error, so allow it to run in settings and then run it again.
% ./speedtest -h
Speedtest by Ookla is the official command line client for testing the speed and performance of your internet connection.
Version: speedtest 1.0.0.2
(---omitted---)
Valid units for [-u] flag:
Decimal prefix, bits per second: bps, kbps, Mbps, Gbps
Decimal prefix, bytes per second: B/s, kB/s, MB/s, GB/s
Binary prefix, bits per second: kibps, Mibps, Gibps
Binary prefix, bytes per second: kiB/s, MiB/s, GiB/s
Auto-scaled prefix: auto-binary-bits, auto-binary-bytes, auto-decimal-bits, auto-decimal-bytes
The help is now displayed.
Now, let's execute the command manually once to retrieve data. I am using an absolute path because I plan to run this via cron later. The absolute path will vary for everyone, so check it using pwd.
From the perspective of subsequent processing, I chose CSV as the output format. I also thought it would be desirable for the connection server to remain the same for comparing data across different time periods, so I fixed it to "OPEN Project (via 20G SINET) - Tokyo (15047)". For my purposes, any server would have worked as long as it was consistent, but please note that measurement results can vary significantly depending on the server.
Since I wanted the CSV header row information, I included the --output-header option only for this manual execution.
% /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest -s 15047 -f csv --output-header >> /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest/speedtest_result.csv 2>&1
% cat /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest/speedtest_result.csv
"server name","server id","latency","jitter","packet loss","download","upload","download bytes","upload bytes","share url"
"OPEN Project (via 20G SINET) - Tokyo","15047","7.14","1.475","0","3457278","4213892","26781160","44256448","https://www.speedtest.net/result/c/dummy123-aa45-6789-1234-5bb6ccc7d89e"
I confirmed that the data was successfully retrieved via manual command execution.
Periodic Execution with cron
Manually executing for 24 hours is difficult and execution times may drift, so I will use cron to execute the command periodically every hour.
I defined the cron job using crontab -e (refer to the crontab -l output below for the definition). I have set it to run the command verified during the manual execution at the 55th minute of every hour. As mentioned above, the --output-header option is not needed, so it has been removed from the cron definition.
I set the execution to the 55th minute to avoid potential high server loads at the beginning of the hour (00 minutes), assuming other people might be running periodic tasks then. Choosing the specific minute is a matter of preference.
% crontab -l
crontab: no crontab for yourusername
% crontab -e
crontab: no crontab for yourusername - using an empty one
crontab: installing new crontab
% crontab -l
55 * * * * /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest -s 15047 -f csv >> /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest_results.csv 2>&1
Checking the output file after the cron execution time, I was able to confirm that the data rows retrieved by the cron execution were appended.
% cat /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest/speedtest_result.csv
"server name","server id","latency","jitter","packet loss","download","upload","download bytes","upload bytes","share url"
"OPEN Project (via 20G SINET) - Tokyo","15047","7.14","1.475","0","3457278","4213892","26781160","44256448","https://www.speedtest.net/result/c/dummy123-aa45-6789-1234-5bb6ccc7d89e"
"OPEN Project (via 20G SINET) - Tokyo","15047","7.245","224.851","2.10526","1623855","4399519","14582582","64562442","https://www.speedtest.net/result/c/dummy789-aa12-3456-7890-1bb2ccc3d45e"
Understanding Internet Connection Speed
Since I obtained the data in CSV format, all that's left is to process the output file as needed using Excel or similar tools.
I wanted to track download and upload speeds, so I used the values from the "download" and "upload" columns in the generated CSV file. Generally, Mbps is the most intuitive format. In that case, you need to convert the units: you can convert the "download" and "upload" values to Mbps by dividing them by 125,000. For example, if the download value is "1,623,855", then 1,623,855 / 125,000 = 12.99084, meaning the download speed is 12.99084 Mbps (approximately 13 Mbps).
Clean-up
Once you have obtained the necessary data, you can stop the periodic execution by removing the cron definition. if you have no other cron jobs besides the one defined this time, you can safely delete everything using crontab -r. If you have other definitions, please use crontab -e to delete only the specific line you want to remove.
% crontab -l
55 * * * * /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest -s 15047 -f csv >> /Users/yourusername/Downloads/ookla-speedtest-1.0.0-macosx/speedtest_results.csv 2>&1
% crontab -r
% crontab -l
crontab: no crontab for yourusername
Discussion
ダウンロード 約 13 Mbps はしんどそうですね
自分は Raspberry Pi で収集しています。仲間がいてうれしいです。
sogaohさん
おお!ラズパイでされていましたか。素晴らしいです。私は短期実行だったのでIntel Macでやったのですが、継続的にデータ取得だとラズパイはいいですね。
ちなみに記事中に書いているように接続先サーバで結構数字にぶれがあるようで、昨日まででシャットダウンしてしまいましたが、ITS-TOKYO (36871)が相手だと71.0~92.3Mbps出ていました。光VDSLなので100Mbspを超えることはないのですが、私の利用用途だと十分使える回線だと感じました。
ありがとうございます!できました!