Banner Image

Measure internet speed with speedtest cli and visualize with R

Apr 9, 2025

Tags:

Info & R Script to use / visualize data generated by the speedtest cli provided ba Ookla.

For details about cli usage please use the documentation, links in script below.
For setting up a cron job to schedule the speedtest please consult the documentation of your OS / distro.

# R script to download data from a machine that operates the speedtest cli
# in this case a Ubuntu machine operates the cli and a Windows machine the R script
# plotly is used to visualize the data

# speedtest cli (from Ookla) available here
# https://www.speedtest.net/de/apps/cli
# schedule via CRON and set parameters and output accordingly
# here we use csv as it's the simplest 

# Note!!! Last used around ~2022, so output of cli might have changed
# adapt R script accordingly

library(ssh)
library(data.table)
library(plotly)

session <- ssh_connect("user@machine", passwd = "my_password")

scp_download(session = session,
             files = c("/home/user/speedtest/speedtest.csv"),
             to = "D:/")

ssh_disconnect(session = session)

speedtest <- fread("D:/speedtest.csv", sep = "\t", fill = TRUE)
# sometime we have NA measurements, connection errors?
speedtest <- speedtest[complete.cases(speedtest), ]

speedtest[, start := as.POSIXct(start)]

# eventually set plot limits to match rated speed range
plot_ly(data = speedtest, type = 'scatter', mode = 'lines',  x=~start, y=~`download (Mbit/s)`, name = 'Download') %>% 
  plotly::add_trace(y=~`upload (Mbit/s)`, name = 'Upload') %>%
  layout(title = 'Download / Upload MY PROVIDER - rated 100 Mbit/s',
         xaxis = list(title = 'Date / Time'),
         yaxis = list(title = 'Mbit/s', range = c(0,110)))