anchor.diff:      end.
   
   
  -%% Format the error message into a binary
  -fmt_to_bin(Str, Args) ->
  -    list_to_binary(lists:flatten(io_lib:format(Str, Args))).
  -
  -
  -%% @doc List of oom errors for each bucket
  --spec oom_errors() -> dict().
  -oom_errors() ->
  +%% @doc list of buckets thats measured stats have increased
  +-spec stat_increased(dict(), dict()) -> list().
  +stat_increased(New, Old) ->
  +    [Bucket || {Bucket, Val} <- dict:to_list(New), increased(Bucket, Val, Old)].
  +
  +
  +%% @doc fetch a list of a stat for all buckets
  +fetch_buckets_stat(Stat) ->
       dict:from_list(
  -      [{Bucket, bucket_oom_errors(Bucket)}
  +      [{Bucket, fetch_bucket_stat(Bucket, Stat)}
          || Bucket <- ns_memcached:active_buckets()]
        ).
   
  -%% @doc Total count of oom errors on a bucket
  --spec bucket_oom_errors(string()) -> integer().
  -bucket_oom_errors(Bucket) ->
  -    case stats_archiver:latest(Bucket, minute, ep_oom_errors) of
  -        {ep_oom_errors, X} -> X;
  +
  +%% @doc fetch latest value of stat for particular bucket
  +fetch_bucket_stat(Bucket, Stat) ->
  +    case stats_archiver:latest(Bucket, minute, Stat) of
  +        {Stat, X} -> X;
           _ -> 0
       end.
   
  
positive.code: %% @doc global checks for any server specific problems locally then
  %% broadcast alerts to clients connected to any particular node
  global_checks() ->
      [oom, ip].
  
  %% @doc fires off various checks
  check_alerts(Opaque, Hist) ->
  
negative.code: %% Amount of time between sending users the same alert (s)
  -define(ALERT_TIMEOUT, 60 * 2).
  
  -export([start_link/0, stop/0, local_alert/2, global_alert/2, fetch_alerts/0]).
  
  
  %% Error constants
  errors(ip) ->
      "Cannot listen on hostname: ~p";
  errors(ep_oom_errors) ->
      "Bucket \"~s\" on node ~s is out of memory";
  errors(ep_item_commit_failed) ->
      "Bucket \"~s\" on node ~s failed to write an item".
  
  %% ------------------------------------------------------------------
  %% API Function Definitions
  