Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[DOC] How to count events in last (n) minutes? #4

Closed
inactivist opened this Issue · 3 comments

2 participants

@inactivist

For example, I'd like to calculate the sum of events over the last five minutes.

I'm using Timeseries in 'count_only' mode because I never care about discrete event data.

Example:

KEY_PREFIX = 'timedata:things'

client = redis.Redis('localhost', 6379)
minute_count = Timeseries(client, {
        'minute':{
            'step':60,              # 60 seconds
            'steps':15,             # last 15 minutes
            'count_only' : True,    # store counts only.
        }
    }, key_prefix=KEY_PREFIX)

def hit(event_id):
    minute_count.insert(event_id, 1)

When events arrive, I call:

    hit('some-event')

Now, I'd like to know the sum of all events recorded in the last 5 minutes (not just the event count in each bucket.)

I think I should be able to sum the items by calling minute_count.series('some-event', 'minute', steps=5, condensed=True) -- is that correct? (I've tried that but I'm having no luck. See issue #3.)

What's the best/recommended way to do this?

@awestendorf
Owner

What you're describing is how I expect it to be used. I'll look into this.

@inactivist

It looks like commit d463f93 fixes this one too. I'll report back ASAP.

@inactivist inactivist closed this
@awestendorf
Owner

Thanks for checking on that. The beta-refactor significantly cleans up the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.