I have a class that dispatches a Success and a Failure event and I need to maintain a statistic on the average number of failure/total number of events in the last X seconds from that class.
I was thinking something along the lines of using a circular linked list and append a success or failure node for each event. Then count the numbers of failure nodes vs. total nodes in the list, but this has two major drawbacks:
- I need to constantly scale the list size up/down to account for the "last X seconds" requirement (the number of events per second can change)
- I need to constantly loop over the list and count all the events (potentially expensive as I will probably have 100s of such events per second)
Does anyone know of another way to compute average values from a list of samples received in the last X seconds?