How are real-time speed and traffic statistics collected?

I’m curious to understand how the real-time speed and traffic statistics are collected?

I guess that the basic data is transmitted and received packet counts across the various router interfaces.

The counts appear to be being sampled every 5 seconds, but what process is sampling? And how are they being recorded? Also, how is the traffic flow allocated to the various clients?

Sorry I do not have an idea about this.