Velocity v0.1.0 Velocity View Source
A simple Elixir.Agent for registering occurrences of different events and reporting event counts for the given time period.
Configuration can be passed to start_link/1 as a keyword list. Supported parameters are:
:ttl- the duration, in seconds, that events should be stored for. Default is 60;:default_period- period to consider by default whenVelocity.of/1is called. Can be either an integer or a@time_rangeskey. Default is :minute.
Anything can be used for event keys. Minimum time granularity is 1 second.
Example
Velocity.start_link(ttl: 3 * 60, default_period: :minute)
Velocity.register(:foo)
Velocity.register(:bar)
Velocity.register(:foo)
Velocity.of(:foo)
#=> {:ok, 2}
Velocity.of(:foo, :minute)
#=> {:ok, 2}
Velocity.of(:bar, :minute)
#=> {:ok, 1}
Velocity.of(:baz, :minute)
#=> {:ok, 0}
#...after 2 minutes...
Velocity.of(:foo, :minute)
#=> {:ok, 0}
Velocity.of(:foo, 5 * 60)
#=> {:ok, 2}
#...after 3 minutes...
Velocity.of(:foo, 5 * 60)
#=> {:ok, 0}
TODO: implement subscribable alerts, e.g. Velocity.alert(self(), :ato, {{:gt, 10}, :minute})
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Reports the number of given events registered within the default time period (see configuration details above).
Reports the number of given events registered within the last period seconds. Pre-defined constants such as :minute or :hour may be used.
Registers occurrence of an event. Anything can be used for the event key.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Reports the number of given events registered within the default time period (see configuration details above).
Reports the number of given events registered within the last period seconds. Pre-defined constants such as :minute or :hour may be used.
Registers occurrence of an event. Anything can be used for the event key.