<commit_before>%% @author Northscale <<EMAIL>>
%% @copyright 2010 NorthScale, Inc.
%% All rights reserved.

-module(stats_aggregator).

-behaviour(gen_server).

-define(SAMPLE_SIZE, 1800).

%% API
-export([start_link/0,
         received_data/5,
         received_topkeys/5,
         get_stats/4,
         get_stats/3,
         get_stats/2,
         get_stats/1,
         get_topkeys/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, {vals, topkeys}).

start_link() ->
    gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).

init([]) ->
    timer:send_interval(60000, garbage_collect),
    {ok, #state{vals=dict:new(), topkeys=dict:new()}}.

handle_call({get, Hostname, Port, Bucket, Count}, _From, State) ->
    Reply = (catch {ok, ringdict:to_dict(Count,
                             dict:fetch({Hostname, Port, Bucket},<commit_msg>Bug 819: Only keep 61 seconds of samples in the stats aggregator<commit_after>%% @author Northscale <<EMAIL>>
%% @copyright 2010 NorthScale, Inc.
%% All rights reserved.

-module(stats_aggregator).

-behaviour(gen_server).

-define(SAMPLE_SIZE, 61).

%% API
-export([start_link/0,
         received_data/5,
         received_topkeys/5,
         get_stats/4,
         get_stats/3,
         get_stats/2,
         get_stats/1,
         get_topkeys/1]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, {vals, topkeys}).

start_link() ->
    gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).

init([]) ->
    timer:send_interval(60000, garbage_collect),
    {ok, #state{vals=dict:new(), topkeys=dict:new()}}.

handle_call({get, Hostname, Port, Bucket, Count}, _From, State) ->
    Reply = (catch {ok, ringdict:to_dict(Count,
                             dict:fetch({Hostname, Port, Bucket},
{'fraction_non_alphanumeric': 0.16035288012454593, 'fraction_numerical': 0.029579657498702647, 'mean_word_length': 3.1373390557939915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3795058', 'n_tokens_mistral': 698, 'n_tokens_neox': 664, 'n_words': 128}