You must use the sampling rate (a-la MRTG). Let's say you only need one second of accuracy and to maintain the average over the last minute, you will have a fixed table of 60 records relating to the past 60 seconds (including the present). And also save the current global record.
Each record consists of an average value and the number of events. Each entry starts at 0 for both values.
When you receive a new event, you change the current and global record as follows:
average = ((number * average) + 1) / (number + 1)
number = number + 1
, :
global.average = ((global.number * global.average) - (oldest.number * oldest.average)) / (global.number - oldest.number)
global.number = global.number - oldest.number
reset 0 .