This version uses OpenTelemetry. Initial versions used OpenCensus
- 2.1.0 - Add OT views with mixed case and spaces in the name - restores the OC names.
- 2.0.1 - Fix crontabe scripts broken directory reorganization
- 2.0.0 - First version with OpenTelemetry
- Unversioned - OpenCensus version - no version info
- The labels for the open telemtry version are those than from the previous version. This is because of the way the OpenTelemetry specification says labels are case insensitive and the Python API converts all labels to lower case with spaces replaced with underscores. The OpenTelemetry Python team may change the casing part of this in the future see open-telemetry/opentelemetry-python#3207 This may be fixible by using views in the same way we did with OpenCensus
- The
--verbose
flag co-mingles the notion of more output and log routing to ApplicationMonitor - This application disables automatic integrations because the metrics and traces are the end product and do not exist as KPIs and diagnostics as part of some greater application.
- This application does not demonstrate cross call tracing identifiers because they weren't needed
This project captures internet connection statistics and sends them to an Azure dashboard.
- Capture the current ping time and optionally upload/doownload statistics of the internet connection for the machine this machine runs on as measured by the
speedtest.net
python API - Publish the results to an Azure Application Insights dashboard
- Python3
- An internet connection
- An account in Azure that can run the free tier of Azure Application Insights. See references below for instructions.
- You can comment out the
AppInsights.py
call at the bottom ofNetCheck.py
if you don't wish to create a dashboard in Azure Application Insights
- You can comment out the
- Create IaC script that instantiates Application Insights so you don't have to use Azure Portal
- Create a script for the Mac that runs
Install Certificates.command
- speedtest.net initialization can vary by platorm. Some machines require https and some don't work with it
- Some Windows WSL environments require
s = speedtest.Speedtest(secure=1)
- The Mac with python 3.10 gets a cert error.
CERTIFICATE_VERIFYFAILED
Two options- Fix the certificate by running the
Install Certificates.command
Double click on/Applications/<python version>/Install Certificates.command
- Disable
secure
with this code changes = speedtest.Speedtest(secure=0)
- Fix the certificate by running the
- Some Windows WSL environments require
Script | Purpose |
---|---|
Linux/Pi Setup/Installation | in Linux-Install |
1-setup-host.sh | downloads the Speedtest.net CLI, configures Python |
2-install-crontab.sh | Installs a crontab entry that runs NetCheck.py on a regular basis |
11-remove-crontab.sh | removes this user's NetCheck.py crontab entries |
Network testing binaries | in src |
NetCheck.py | The main program. Program that invokes the test code in SpeedTest.py |
SpeedTest.py | SpeedTest.net adapter. Runs the speedtest-cli and records metrics |
AppInsights.py | OpenCensus library wrapper used to send metrics to Azure Application Insights |
Windows Python Setup | |
setup.ps1 | Windows Python setup program. Will prompt to install python3 via Windows store |
-
Run
1-setup-host.sh
to install dependencies on a raspberry pi- Alternative for like a windows machine
pip3 install -r requirements.txt
orpython3 -m pip install -r requirements.txt
- Alternative for like a windows machine
-
Create Application Inights and get key
- Get an Azure account
- Log into Azure Portal Insights blade
- Register in Application Insights
- Select your subscription
- Create a resource group or use an existing one
- Select an instance name.
- Select a Region.
- Select Resource Mode as a _Workspace-based.
- Select the Log Analytics Workspace. There is a DefaultWorkspace in each region. You can use that.
- Get an Application Insights Instrumentation Key from the Portal. It is on the Application Insights home page in the upper right corner.
- Open the Application Insights blade
- Copy the
Connection String
in the upper right corder
- Copy config.ini.template to config.ini
- Replace the dummy key in config.ini with your new key that you copied from the portal above. It should look something like
azure_instrumentation_key=InstrumentationKey=0000000-0000-0000-0000-00000000000;IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/
-
Run main program
NetCheck.py
There are several options- Run with only a ping check
python3 src/NetCheck.py
- Run with ping, upload and download
python3 src/NetCheck.py --download --upload
- Get help with
python3 src/NetCheck.py --help
- Run with only a ping check
- Manage data retention the data retention period. Learn how long data is kept.
- cd into this directory
- Verify the cycle times you wish in
2-install-crontab.sh
. The file is in crontab format. - run
2-install-crontab.sh
Sample crontab -l
output after installing the crontab
pi@pi-153a3987b:~/Documents/speedtest-app-insights $ crontab -l
*/3 * * * * cd /home/pi/Documents/speedtest-app-insights && python3 NetCheck.py
13 */4 * * * cd /home/pi/Documents/speedtest-app-insights && python3 NetCheck.py --upload --download
*/6 * * * * cd /home/pi/Documents/speedtest-app-insights && python3 DnsCheck.py
Raspberry Pi3 on 1GB port on 1GB FIOS internet service.
Installed in /usr/bin
pi@pi-52863f1:~/Documents/speedtest-app-insights $ /usr/bin/speedtest
Speedtest by Ookla
Server: Windstream - Ashburn, VA (id = 17383)
ISP: Verizon Fios
Latency: 4.04 ms (0.04 ms jitter)
Download: 94.19 Mbps (data used: 42.4 MB)
Upload: 93.90 Mbps (data used: 42.3 MB)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/dee19d27-1f5a-4cff-aa42-d8084a145b8f
Installed in ~/.local/bin
$ speedtest
Retrieving speedtest.net configuration...
Testing from Verizon Fios (108.48.69.33)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by PBW Communications, LLC (Herndon, VA) [22.70 km]: 8.306 ms
Testing download speed................................................................................
Download: 91.92 Mbit/s
Testing upload speed......................................................................................................
Upload: 93.90 Mbit/s
See Application Insights Readme
Some Raspberry Pi models are speed limited on their ethernet. magpi posted ethernet test results
- In my testing, the Raspberry Pi 3 hardwire Ethernet seems to max out about 94 Mbit/s. The Raspberry Pi speed should be sigficantly higher because its eithernet interface is part of the SoC instead of being USB attached like previous boards.
- My results align with numbers in this blog article https://www.jeffgeerling.com/blogs/jeff-geerling/getting-gigabit-networking . The same article says you can get slightly over 200 Mbit/s with a USB 3.0 Gigabit adapter.
- This site shows Raspberry Pi 3 and Pi 4 speeds. Note that the Pi3 speeds on this page are higher than other reference sites Hackaday Raspberry Pi Benchmarks
- Speedtest Python library
This module uses dnspython to do a dns check. I found that my network experience was heavily driven by my DNS times.
It should install fine but you can see in 1-setup-host.sh that there is a bit of overhead to get this working because it depends on a library that is best installed from git.
The speed test team changes something in their API in April 2021. This changed some format that broke speedtest.py. You need the 2.1.3 version, or later, of the speedtest. Grab it with pip3 or if not available then the following assuming you run pip not as root
wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py -O ~/.local/lib/python3.<version>/site-packages/speedtest.py
Ex:
wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py -O ~/.local/lib/python3.7/site-packages/speedtest.py