anchor.diff:      NumConnections = proplists:get_value(index_num_connections, Status, 0),
       NeedsRestart = proplists:get_value(index_needs_restart, Status, false),
       index_status_keeper:update(NumConnections, NeedsRestart, Indexes),
  -    BucketStats = aggregate_index_stats([{B, K, V} || {{B, _, _} = K, V} <- Stats]),
  -    PerBucketStats = misc:keygroup(1, BucketStats),
  -    [begin
  -         Values = lists:keysort(1, [{format_k(K), V} || {_, K, V} <- S]),
  -         gen_event:notify(ns_stats_event,
  -                          {stats, "@index-"++binary_to_list(B),
  -                           #stat_entry{timestamp = TS,
  -                                       values = Values}})
  -     end || {B, S} <- PerBucketStats],
  +
  +    lists:foreach(
  +      fun ({Bucket, BucketStats}) ->
  +              gen_event:notify(ns_stats_event,
  +                               {stats, "@index-"++binary_to_list(Bucket),
  +                                #stat_entry{timestamp = TS,
  +                                            values = BucketStats}})
  +      end, aggregate_index_stats(Stats)),
  +
       {noreply, #state{prev_counters = NewCounters,
                        prev_ts = TS}};
   handle_info(_Info, State) ->
       {noreply, State}.
   
  -format_k({_Bucket, Index, Metric}) ->
  -    per_index_stat(Index, Metric);
  -format_k(Metric) when is_binary(Metric) ->
  -    global_index_stat(Metric).
  -
   per_index_stat(Index, Metric) ->
       iolist_to_binary([<<"index/">>, Index, $/, Metric]).
   
  
positive.code:     Stats = lists:merge(Stats0, lists:sort(StatsGauges)),
      {Stats, StatsCounters, Status}.
  
  aggregate_index_stats([]) ->
      [];
  aggregate_index_stats([{B, {_B, _I, K}, V} = Triple | Rest]) ->
      [Triple | aggregate_index_stats_loop(B, [{B, K, V}], Rest)].
  
  aggregate_index_stats_loop(B, Acc, [{B2, {_B, _I, K}, V} = Triple | Rest] = List) ->
      case B =:= B2 of
          true ->
              Acc2 = case lists:keyfind(K, 2, Acc) of
                         false ->
                             [{B, K, V} | Acc];
                         {_B, _K, AccV} ->
                             lists:keyreplace(K, 2, Acc, {B, K, AccV + V})
                     end,
              [Triple | aggregate_index_stats_loop(B, Acc2, Rest)];
          false ->
              lists:reverse(Acc) ++ aggregate_index_stats(List)
      end;
  aggregate_index_stats_loop(_B, Acc, []) ->
      lists:reverse(Acc).
  
  aggregate_index_stats_test() ->
      In = [{{<<"a">>, <<"idx1">>, <<"m1">>}, 1},
  
negative.code:           {{<<"b">>, <<"idx2">>, <<"m2">>}, 4},
            {{<<"b">>, <<"idx3">>, <<"m1">>}, 5},
            {{<<"b">>, <<"idx3">>, <<"m2">>}, 6}],
      Out = aggregate_index_stats(In),
  
      AStats0 = [{<<"index/idx1/m1">>, 1},
                 {<<"index/idx1/m2">>, 2},
                 {<<"index/m1">>, 1},
                 {<<"index/m2">>, 2}],
      BStats0 = [{<<"index/idx2/m1">>, 3},
                 {<<"index/idx2/m2">>, 4},
                 {<<"index/idx3/m1">>, 5},
                 {<<"index/idx3/m2">>, 6},
                 {<<"index/m1">>, 3+5},
                 {<<"index/m2">>, 4+6}],
  
      AStats = lists:keysort(1, AStats0),
      BStats = lists:keysort(1, BStats0),
  
      ?assertEqual(Out,
                   [{<<"b">>, BStats},
                    {<<"a">>, AStats}]).
  
  handle_info({tick, TS0}, #state{prev_counters = PrevCounters,
                                  prev_ts = PrevTS}) ->
  