Is there a way to avoid the thread and the data storage? I'd like to keep the footprint of the monitoring code as small as possible: no extra threads, as little extra memory as possible. 

If there is no other way, then OK; but can anyone else take a look at it?