Commits

Anonymous committed 85c20b6

riak_stat also counting number of gets and puts coordinated by a node

Comments (0)

Files changed (3)

src/riak_get_fsm.erl

     case length(Replied) >= R of
         true ->
             Final = respond(Client,Replied,AllowMult,ReqId),
+            riak_stat:update(node_get),
             case Final of
                 {error, notfound} ->
                     riak_eventer:notify(riak_get_fsm, get_fsm_reply,
         true ->
             {next_state,waiting_vnode_r,NewStateData,End-riak_util:moment()};
         false ->
+            riak_stat:update(node_get),
             riak_eventer:notify(riak_get_fsm, get_fsm_reply,
                                 {ReqId, notfound}),
             Client ! {ReqId, {error,notfound}},
             case length(NotFound) of
                 0 ->
                     FullErr = [E || {E,_I} <- Replied],
+                    riak_stat:update(node_get),
                     riak_eventer:notify(riak_get_fsm, get_fsm_reply,
                                         {ReqId, {error,FullErr}}),
                     Client ! {ReqId, {error,FullErr}},
                     {stop,normal,NewStateData};
                 _ ->
+                    riak_stat:update(node_get),
                     riak_eventer:notify(riak_get_fsm, get_fsm_reply,
                                         {ReqId, notfound}),
                     Client ! {ReqId, {error,notfound}},
             end
     end;
 waiting_vnode_r(timeout, StateData=#state{client=Client,req_id=ReqId}) ->
+    riak_stat:update(node_get),
     riak_eventer:notify(riak_get_fsm, get_fsm_reply,
                         {ReqId, timeout}),
     Client ! {ReqId, {error,timeout}},

src/riak_put_fsm.erl

             case DW of
                 0 ->
                     Client ! {ReqId, ok},
+                    riak_stat:update(node_put),
                     riak_eventer:notify(riak_put_fsm, put_fsm_reply_ok,
                                         {ReqId, ok, {Bucket, Key}}),
                     {stop,normal,StateData};
         true ->
             {next_state,waiting_vnode_w,NewStateData,End-riak_util:moment()};
         false ->
+            riak_stat:update(node_put),
             riak_eventer:notify(riak_put_fsm, put_fsm_reply,
                                 {ReqId, {error,too_many_fails,Replied}}),
             Client ! {ReqId, {error,too_many_fails}},
             {stop,normal,NewStateData}
     end;
 waiting_vnode_w(timeout, StateData=#state{client=Client,req_id=ReqId}) ->
+    riak_stat:update(node_put),
     riak_eventer:notify(riak_put_fsm, put_fsm_reply,
                         {ReqId, {error,timeout}}),
     Client ! {ReqId, {error,timeout}},
     Replied = [Idx|Replied0],
     case length(Replied) >= DW of
         true ->
+            riak_stat:update(node_put),
             riak_eventer:notify(riak_put_fsm, put_fsm_reply_ok,
                                 {ReqId, ok, {Bucket, Key}}),
             Client ! {ReqId, ok},
             {stop,normal,NewStateData}
     end;
 waiting_vnode_dw(timeout, StateData=#state{client=Client,req_id=ReqId}) ->
+    riak_stat:update(node_put),
     riak_eventer:notify(riak_put_fsm, put_fsm_reply,
                         {ReqId, {error,timeout}}),
     Client ! {ReqId, {error,timeout}},

src/riak_stat.erl

 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
          terminate/2, code_change/3]).
 
--record(state,{vnode_gets,vnode_puts}).
+-record(state,{vnode_gets,vnode_puts,
+               node_gets,node_puts}).
 
 %%====================================================================
 %% API
 %%--------------------------------------------------------------------
 init([]) ->
     {ok, #state{vnode_gets=spiraltime:fresh(),
-                vnode_puts=spiraltime:fresh()}}.
+                vnode_puts=spiraltime:fresh(),
+                node_gets=spiraltime:fresh(),
+                node_puts=spiraltime:fresh()}}.
 
 %%--------------------------------------------------------------------
 %% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
     spiral_incr(#state.vnode_gets, Moment, State);
 update(vnode_put, Moment, State) ->
     spiral_incr(#state.vnode_puts, Moment, State);
+update(node_get, Moment, State) ->
+    spiral_incr(#state.node_gets, Moment, State);
+update(node_put, Moment, State) ->
+    spiral_incr(#state.node_puts, Moment, State);
 update(_, _, State) ->
     State.
 
     Moment = spiraltime:n(),
     lists:append(
       [vnode_stats(Moment, State),
+       node_stats(Moment, State),
        cpu_stats(),
        mem_stats(),
        disk_stats()]).
      || {F, Elt} <- [{vnode_gets, #state.vnode_gets},
                      {vnode_puts, #state.vnode_puts}]].
 
+node_stats(Moment, State) ->
+    [{F, spiral_minute(Moment, Elt, State)}
+     || {F, Elt} <- [{node_gets, #state.node_gets},
+                     {node_puts, #state.node_puts}]].
+
 cpu_stats() ->
     [{cpu_nprocs, cpu_sup:nprocs()},
      {cpu_avg1, cpu_sup:avg1()},