Calculate stats like iostat and use counters to store it in a file https://github.com/sysstat/sysstat/blob/master/iostat.c