Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 2.64 KB

README.md

File metadata and controls

76 lines (57 loc) · 2.64 KB

savanna_commons

Build Status

An original statistics library, which is able to easily realize to calculate statistics such as counter and histogram.

Usage

-behaviour(svc_notify_behaviour).
-include("savanna_commons.hrl").

notify(Schema, {Key, Values}) ->
    io:format("schema:~w, key:~w, value:~p",
              [SchemaName, Key, Value]),
    ok.

sample() ->
    %% Start "mnesia"
    mnesia:start(),

    %% Start savanna_commons's supervisor
    {ok,_Pid} = savanna_commons_sup:start_link(),

    %% Create tables in order to manage the statistics-schemas
    {atomic,ok} = svc_tbl_schema:create_table(ram_copies, [node()]),
    {atomic,ok} = svc_tbl_column:create_table(ram_copies, [node()]),
    {atomic,ok} = svc_tbl_metric_group:create_table(ram_copies, [node()]),

    %% Create a schema
    SchemaName = 'test_1',
    ok = savanna_commons:create_schema(
            SchemaName, [#sv_column{name = 'col_1',
                                    type = ?COL_TYPE_COUNTER,
                                    constraint = []},
                         #sv_column{name = 'col_2',
                                    type = ?COL_TYPE_H_UNIFORM,
                                    constraint = [{?HISTOGRAM_CONS_SAMPLE, 3000}]}
                        ]),

    %% Create a metric by the schema
    Window = 10,
    ok = savanna_commons:create_metrics_by_schema(SchemaName, Window, ?MODULE),

    %% Notify events for a column (Counter)
    Key_1 = 'col_1',
    savanna_commons:notify(Schema, {Key_1,  128}),
    savanna_commons:notify(Schema, {Key_1,  256}),
    savanna_commons:notify(Schema, {Key_1,  384}),
    savanna_commons:notify(Schema, {Key_1,  512}),
    savanna_commons:notify(Schema, {Key_1, 1024}),

    %% Notify events for a column (Histogram)
    Key_2 = 'col_2',
    savanna_commons:notify(Schema, {Key_2,  16}),
    savanna_commons:notify(Schema, {Key_2,  32}),
    savanna_commons:notify(Schema, {Key_2,  64}),
    savanna_commons:notify(Schema, {Key_2, 128}),
    savanna_commons:notify(Schema, {Key_2, 256}),

    %% Retrieve stats
    {ok, _Ret_1} = savanna_commons:get_metric_value(Schema, Key_1),
    {ok, _Ret_2} = savanna_commons:get_histogram_statistics(Schema, Key_2),
    ok.

License

savanna_commons's license is Apache License Version 2.0

Sponsors