From 6db9b414ed924e4f5d28ff06faacd68917a0a9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81mar=20Kjartan=20Yasin?= Date: Wed, 27 Nov 2013 15:58:50 -0800 Subject: [PATCH] Log down the redis url with the number of dropped count. --- src/logplex_queue.erl | 11 ++++++++++- src/logplex_stats.erl | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/logplex_queue.erl b/src/logplex_queue.erl index 7de25e5d..d9c6e649 100644 --- a/src/logplex_queue.erl +++ b/src/logplex_queue.erl @@ -85,6 +85,8 @@ out(NameOrPid, Num) when (is_atom(NameOrPid) orelse is_pid(NameOrPid)) andalso i Packet end. +-spec info(atom()|pid()) -> + {pos_integer(), pos_integer()}. info(NameOrPid) when is_atom(NameOrPid); is_pid(NameOrPid) -> gen_server:call(NameOrPid, info, ?TIMEOUT). @@ -174,8 +176,15 @@ handle_call(_Msg, _From, State) -> %% @hidden %%-------------------------------------------------------------------- handle_cast({in, _Packet}, #state{dict=Dict, dropped_stat_key=StatKey, length=Length, max_length=MaxLength, num_dropped=NumDropped}=State) when Length >= MaxLength -> - logplex_stats:incr(StatKey), logplex_realtime:incr(StatKey), + RedisUrl = case dict:find(redis_url, Dict) of + {ok, Value} -> + Value; + undefined -> + undefined + end, + logplex_stats:incr(#queue_stat{key=StatKey, + redis_url=RedisUrl}), case dict:find(producer_callback, Dict) of {ok, Fun} -> Fun(self(), stop_accepting); error -> ok diff --git a/src/logplex_stats.erl b/src/logplex_stats.erl index 1ac3081f..a68e7bf4 100644 --- a/src/logplex_stats.erl +++ b/src/logplex_stats.erl @@ -42,8 +42,8 @@ incr(Key) -> incr(Key, 1). -spec incr(#drain_stat{} | #channel_stat{} | #logplex_stat{} | - list() | atom(), - integer()) -> any(). + #queue_stat{} | list() | atom(), integer()) -> + any(). incr(Key, Incr) when is_integer(Incr) -> try ets:update_counter(?MODULE, Key, Incr) catch error:badarg -> @@ -163,6 +163,10 @@ log_stat(UnixTS, #logplex_stat{module=Mod, key=K}, Val) -> io:format("m=logplex_stats ts=~p system module=~p ~200p=~p~n", [UnixTS, Mod, K, Val]); +log_stat(UnixTS, #queue_stat{redis_url=RedisUrl, key=Key}, Val) -> + io:format("m=logplex_stats ts=~p redis_url=~p ~p=~p~n", + [UnixTS, RedisUrl, Key, Val]); + log_stat(UnixTS, {Class, Key}, Val) -> io:format("m=logplex_stats ts=~p freeform class=~p key=~p count=~p~n", [UnixTS, Class, Key, Val]);