elib/ernie_server.erl in mojombo-ernie-0.3.3 vs elib/ernie_server.erl in mojombo-ernie-0.3.4

- old
+ new

@@ -7,11 +7,12 @@ %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -record(state, {lsock = undefined, - pending = queue:new()}). + pending = queue:new(), + count = 0}). -record(request, {sock = undefined, info = undefined, action = undefined}). @@ -68,11 +69,13 @@ %% Description: Handling cast messages %%-------------------------------------------------------------------- handle_cast({process, Sock}, State) -> Request = #request{sock = Sock}, State2 = receive_term(Request, State), - {noreply, State2}; + Count = State2#state.count, + State3 = State2#state{count = Count + 1}, + {noreply, State3}; handle_cast({asset_freed}, State) -> case queue:is_empty(State#state.pending) of false -> case asset_pool:lease() of {ok, Asset} -> @@ -125,14 +128,16 @@ asset_pool:reload_assets(), gen_tcp:send(Sock, term_to_binary({reply, <<"Handlers reloaded.">>})), ok = gen_tcp:close(Sock), State; process_admin(Sock, stats, _Args, State) -> + Count = State#state.count, + CountString = list_to_binary([<<"connections.total=">>, integer_to_list(Count), <<"\n">>]), IdleWorkers = asset_pool:idle_worker_count(), - IdleWorkersString = list_to_binary([<<"idle workers: ">>, integer_to_list(IdleWorkers), <<"\n">>]), + IdleWorkersString = list_to_binary([<<"workers.idle=">>, integer_to_list(IdleWorkers), <<"\n">>]), QueueLength = queue:len(State#state.pending), - QueueLengthString = list_to_binary([<<"pending connections: ">>, integer_to_list(QueueLength), <<"\n">>]), - gen_tcp:send(Sock, term_to_binary({reply, list_to_binary([IdleWorkersString, QueueLengthString])})), + QueueLengthString = list_to_binary([<<"connections.pending=">>, integer_to_list(QueueLength), <<"\n">>]), + gen_tcp:send(Sock, term_to_binary({reply, list_to_binary([CountString, IdleWorkersString, QueueLengthString])})), ok = gen_tcp:close(Sock), State; process_admin(Sock, _Fun, _Args, State) -> gen_tcp:send(Sock, term_to_binary({reply, <<"Admin function not supported.">>})), ok = gen_tcp:close(Sock), \ No newline at end of file