stats_agg v0.1.5 Ciroque.Monitoring.StatsAgg
Records and calculates statistics for function execution durations.
Summary
Types
Defines the maps that are acceptable to the record duration implementation
Functions
Stores the given duration
Retrieves the current snapshot of the stats that have been logged
Starts the StatsAgg process with the default state (an empty map, e.g. - %{}
)
Starts the StatsAgg process with the provided state
Types
record_function_duration_args_t ::
%{group: String.t, module: String.t, function: String.t, duration: integer} |
%{group: String.t, module: String.t, function: String.t, started_at: integer, ended_at: integer}
Defines the maps that are acceptable to the record duration implementation.
The duration version is straight forward.
The started_at
/ ended_at
version calculates the duration using the provided values. These values
should be integers. os:system_time(:millisecond)
is the intended — and tested — case, though
os:system_time(:microsecond)
should work.
String formatted Date / Times are not supported at this time.
Functions
Stores the given duration.
As noted in the record_function_duration_args_t
section, there are two versions of this method.
The first takes the duration.
Example
iex> args = %{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", duration: 1200 }
%{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", duration: 1200 }
iex> :ok = StatsAgg.record_function_duration(args)
:ok
The second takes the started_at and ended_at values as integers.
Example
iex> args = %{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", started_at: 1514331128740, ended_at: 1514331139316 }
%{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", started_at: 1514331128740, ended_at: 1514331139316 }
iex> :ok = StatsAgg.record_function_duration(args)
:ok
Returns: :ok
The method is asychronous.
Retrieves the current snapshot of the stats that have been logged.
The query
paramater is a list of keys to be searched. The items are, in order,
group
, module
, function
.
The returned value is a list of items with the following shape:
%{
avg_duration: integer,
durations: list(integer),
function: String.t,
group: String.t,
max_duration: integer,
min_duration: integer,
module: String.t,
most_recent_duration: integer,
}
Example
iex> args = %{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", duration: 1200 }
%{ group: "MyGroup", module: "Elixir.Ciroque.Monitoring.StatsAgg", function: "function/0", duration: 1200 }
iex> :ok = StatsAgg.record_function_duration(args)
:ok
iex> query = ["MyGroup"]
["MyGroup"]
iex> StatsAgg.retrieve_stats(query)
[%{avg_duration: 1200, durations: [1200], function: "function/0",
group: "MyGroup", max_duration: 1200, min_duration: 1200,
module: "Elixir.Ciroque.Monitoring.StatsAgg",
most_recent_duration: 1200}]