Konubinix' opinionated web of thoughts

Live Plot My 4g Connection

Fleeting

using gnuplot

I needed to watch my connection while working at home, because my internet connection broke and I only relied on my limited 4g network.

The data looks like this

2025-06-05T09:44:31+02:00,15.101
2025-06-05T09:44:37+02:00,15.103
2025-06-05T09:44:43+02:00,15.103
2025-06-05T09:44:49+02:00,15.103
...

Unfortunately, gnuplot does not deal with time zones1, so I eventually dumped the data using timestamps, so more like:

1749458884,21.684
1749458889,21.684
1749458894,21.684
1749458899,21.684
1749458904,21.684
...

This is some code that shows the data and some fitting to have some hints about how fast the data is spent. It is quite hard to read…

number_of_minutes = 20
connection_limit = 80 # Gio
localization = 3600 * 2

set datafile separator ","
set xdata time
set timefmt "%s"
timeformat = "%a %H:%M:%S"
set format x timeformat
set xtics rotate by -45
set border linewidth 1
set style line 1 lc rgb '#0060aa' lt 1 lw 2 pt 7 pi 0 ps 0.7
set terminal qt enhanced font 'Fira Sans,11'

set ylabel "Gio"
set title sprintf("Remaining data (last %d minutes)", number_of_minutes)
set grid

while (1) {
    now = time(0)
    start_of_graph = now - number_of_minutes*60

    f(x) = a * x + b
    a=1
    b=1

    # fit only the positive values, translating x so that t=0 is twenty minutes
    # ago. This will make it fit correctly, while big values like the number of
    # seconds since epoch will lead to bad fitting due to floating point errors.
    fit[0:] f(x) "/home/sam/test/next/conn.csv" using ($1-start_of_graph):(connection_limit-$2) via a, b

    # only show the data from the last twenty
    set xrange [start_of_graph+localization:now+localization]

    time_reaching_0 = -b/a+start_of_graph
    remaining_time = int(time_reaching_0-now)
    remaining_time_hours = int(remaining_time / 3600)
    remaining_time_minutes = int((remaining_time % 3600) / 60)
    remaining_time_seconds = int(remaining_time % 60)


    set xlabel sprintf("slope: %d k/s, %dh %dm %ds, %s", a * 1024 * 1024, remaining_time_hours, remaining_time_minutes, remaining_time_seconds ,strftime("%a %d %b %H:%M:%S", time_reaching_0+localization))
    plot "/home/sam/test/next/conn.csv" using ($1+localization):(connection_limit-$2) with linespoints ls 1 title sprintf("4g"), \
         f(x-start_of_graph-localization) title sprintf("fit")


    pause 3
}

Then, call it with

gnuplot plot.gnuplot

It then looks like this:

Now, I have a better visualization of how far I am from consuming all my data.


  1. There is no provision for changing the time zone or for daylight savings. If all your data refer to the same time zone (and are all either daylight or standard) you don’t need to worry about these things. But if the absolute time is crucial for your application, you’ll need to convert to UT yourself.

    http://gnuplot.info/docs/loc4359.html ([2025-06-05 Thu])

     ↩︎