Skip to content

Commit

Permalink
WHISTLE-1441: more stats instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
James Aimonetti committed Sep 9, 2012
1 parent 00b8e8e commit d8b763e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
45 changes: 32 additions & 13 deletions whistle_apps/apps/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ ringing({channel_hungup, CallId}
,acct_id=AcctId
,agent_id=AgentId
,member_call_queue_id=QueueId
,member_call_id=CallId
,member_call_id=MCallId
}=State) ->
lager:debug("agent channel was destroyed before we could connect: ~s", [CallId]),

acdc_agent:channel_hungup(Srv, CallId),
acdc_agent:member_connect_retry(Srv),
acdc_stats:call_missed(AcctId, QueueId, AgentId, CallId),
acdc_stats:call_missed(AcctId, QueueId, AgentId, MCallId),

{next_state, ready, clear_call(State)};

ringing({channel_hungup, CallId}
,#state{agent_proc=Srv
,member_call_id=CallId
Expand Down Expand Up @@ -472,10 +472,19 @@ answered({channel_hungup, CallId}
,#state{wrapup_timeout=WrapupTimeout
,agent_proc=Srv
,agent_call_id=CallId
,member_call_id=MCallId
,member_call_queue_id=QueueId
,member_call_start=Started
,acct_id=AcctId
,agent_id=AgentId
}=State
) ->
lager:debug("agent call has hungup, going into a wrapup period ~p: ~s", [WrapupTimeout, CallId]),

acdc_stats:call_processed(AcctId, QueueId, AgentId
,MCallId, wh_util:elapsed_s(Started)
),

acdc_agent:channel_hungup(Srv, CallId),
Ref = start_wrapup_timer(WrapupTimeout),

Expand All @@ -485,35 +494,45 @@ answered({channel_hungup, CallId}
,#state{wrapup_timeout=WrapupTimeout
,agent_proc=Srv
,member_call_id=CallId
,member_call_start=Started
,member_call_queue_id=QueueId
,member_call_start=Started
,acct_id=AcctId
,agent_id=AgentId
}=State
) ->
lager:debug("member call has hungup, going into a wrapup period ~p: ~s", [WrapupTimeout, CallId]),

acdc_agent:channel_hungup(Srv, CallId),
Ref = start_wrapup_timer(WrapupTimeout),

acdc_stats:call_processed(AcctId, QueueId, AgentId
,CallId, wh_util:elapsed_s(Started)
),

acdc_agent:channel_hungup(Srv, CallId),
Ref = start_wrapup_timer(WrapupTimeout),

{next_state, wrapup, State#state{wrapup_timeout=undefined, wrapup_ref=Ref}};

answered({channel_hungup, CallId}, #state{agent_proc=Srv}=State) ->
lager:debug("someone(~s) hungup, who cares"),
acdc_agent:channel_hungup(Srv, CallId),
{next_state, answered, State};

answered({channel_unbridged, CallId}, #state{member_call_id=CallId}=State) ->
lager:debug("member unbridged"),
{next_state, answered, State};
%% answered({channel_unbridged, CallId}, #state{member_call_id=CallId
%% ,acct_id=AcctId
%% ,member_call_queue_id=QueueId
%% ,agent_id=AgentId
%% ,member_call_start=Started
%% }=State) ->
%% lager:debug("member unbridged"),

answered({channel_unbridged, CallId}, #state{agent_call_id=CallId}=State) ->
lager:debug("agent unbridged"),
{next_state, answered, State};
%% acdc_stats:call_processed(AcctId, QueueId, AgentId
%% ,CallId, wh_util:elapsed_s(Started)
%% ),

%% {next_state, answered, State};

%% answered({channel_unbridged, CallId}, #state{agent_call_id=CallId}=State) ->
%% lager:debug("agent unbridged"),
%% {next_state, answered, State};

answered({sync_req, JObj}
,#state{agent_proc=Srv
Expand Down
2 changes: 2 additions & 0 deletions whistle_apps/apps/acdc/src/acdc_agent_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ maybe_start_agent(AcctId, AgentId) ->
lager:debug("agent ~s (~s) not found, starting", [AgentId, AcctId]),
{ok, AgentJObj} = couch_mgr:open_doc(wh_util:format_account_id(AcctId, encoded), AgentId),
_R = acdc_agents_sup:new(AgentJObj),
acdc_stats:agent_active(AcctId, AgentId),
lager:debug("started agent at ~p", [_R]);
P when is_pid(P) ->
lager:debug("agent ~s (~s) already running: supervisor ~p", [AgentId, AcctId, P])
Expand All @@ -58,6 +59,7 @@ maybe_stop_agent(AcctId, AgentId) ->
case acdc_agents_sup:find_agent_supervisor(AcctId, AgentId) of
undefined -> lager:debug("agent ~s (~s) not found, nothing to do", [AgentId, AcctId]);
P when is_pid(P) ->
acdc_stats:agent_inactive(AcctId, AgentId),
acdc_agent_sup:stop(P)
end.

Expand Down
13 changes: 12 additions & 1 deletion whistle_apps/apps/acdc/src/acdc_queue_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
,agent_ring_timer_ref :: reference() % how long to ring an agent before moving to the next

,member_call :: whapps_call:call()
,member_call_start :: wh_now()

%% Config options
,name :: ne_binary()
Expand Down Expand Up @@ -265,6 +266,7 @@ ready({member_call, CallJObj, Delivery}, #state{queue_proc=Srv

{next_state, connect_req, State#state{collect_ref=start_collect_timer()
,member_call=Call
,member_call_start=erlang:now()
,connection_timer_ref=start_connection_timer(ConnTimeout)
}};
ready({agent_resp, _Resp}, State) ->
Expand Down Expand Up @@ -389,9 +391,17 @@ connecting({agent_resp, _Resp}, State) ->
lager:debug("agent resp must have just missed cutoff: ~p", [_Resp]),
{next_state, connecting, State};

connecting({accepted, AcceptJObj}, #state{queue_proc=Srv}=State) ->
connecting({accepted, AcceptJObj}, #state{queue_proc=Srv
,member_call_start=Start
,member_call=Call
,acct_id=AcctId
,queue_id=QueueId
}=State) ->
lager:debug("recv acceptance from agent: ~p", [AcceptJObj]),
acdc_queue:finish_member_call(Srv, AcceptJObj),
acdc_stats:call_handled(AcctId, QueueId
,whapps_call:call_id(Call), wh_util:elapsed_s(Start)
),
{next_state, ready, clear_member_call(State)};

connecting({retry, RetryJObj}, #state{queue_proc=Srv, connect_resps=[]}=State) ->
Expand Down Expand Up @@ -620,6 +630,7 @@ clear_member_call(#state{connection_timer_ref=ConnRef
,member_call=undefined
,connection_timer_ref=undefined
,agent_ring_timer_ref=undefined
,member_call_start=undefined
}.

update_properties(QueueJObj, State) ->
Expand Down

0 comments on commit d8b763e

Please sign in to comment.