Update to use couch_stats
diff --git a/priv/stats_descriptions.cfg b/priv/stats_descriptions.cfg
new file mode 100644
index 0000000..beb5248
--- /dev/null
+++ b/priv/stats_descriptions.cfg
@@ -0,0 +1,20 @@
+{[global_changes, db_writes], [
+    {type, counter},
+    {desc, <<"number of db writes performed by global changes">>}
+]}.
+{[global_changes, event_doc_conflict], [
+    {type, counter},
+    {desc, <<"number of conflicted event docs encountered by global changes">>}
+]}.
+{[global_changes, listener_pending_updates], [
+    {type, gauge},
+    {desc, <<"number of global changes updates pending writes in global_changes_listener">>}
+]}.
+{[global_changes, rpcs], [
+    {type, counter},
+    {desc, <<"number of rpc operations performed by global_changes">>}
+]}.
+{[global_changes, server_pending_updates], [
+    {type, gauge},
+    {desc, <<"number of global changes updates pending writes in global_changes_server">>}
+]}.
diff --git a/src/global_changes.app.src b/src/global_changes.app.src
index ce34a80..4fb9a92 100644
--- a/src/global_changes.app.src
+++ b/src/global_changes.app.src
@@ -19,6 +19,7 @@
         stdlib,
         config,
         couch_log,
+        couch_stats,
         couch,
         mem3,
         fabric
diff --git a/src/global_changes_listener.erl b/src/global_changes_listener.erl
index 9befdfd..87a0268 100644
--- a/src/global_changes_listener.erl
+++ b/src/global_changes_listener.erl
@@ -80,6 +80,10 @@
             EventBin = erlang:atom_to_binary(Event, latin1),
             Key = <<EventBin/binary, <<":">>/binary, DbName/binary>>,
             Pending = sets:add_element(Key, State0#state.pending_updates),
+            couch_stats:update_gauge(
+                [global_changes, listener_pending_updates],
+                Count + 1
+            ),
             State0#state{pending_updates=Pending, pending_update_count=Count+1}
     end,
     maybe_send_updates(State);
@@ -122,11 +126,16 @@
             try group_updates_by_node(State#state.dbname, Updates) of
                 Grouped ->
                     dict:map(fun(Node, Docs) ->
+                        couch_stats:increment_counter([global_changes, rpcs]),
                         global_changes_server:update_docs(Node, Docs)
                     end, Grouped)
             catch error:database_does_not_exist ->
                 ok
             end,
+            couch_stats:update_gauge(
+                [global_changes, listener_pending_updates],
+                0
+            ),
             State1 = State#state{
                 pending_updates=sets:new(),
                 pending_update_count=0,
diff --git a/src/global_changes_server.erl b/src/global_changes_server.erl
index 5312459..812d6da 100644
--- a/src/global_changes_server.erl
+++ b/src/global_changes_server.erl
@@ -87,9 +87,14 @@
     {noreply, State};
 handle_cast({update_docs, DocIds}, State) ->
     Pending = sets:union(sets:from_list(DocIds), State#state.pending_updates),
+    PendingCount = sets:size(Pending),
+    couch_stats:update_gauge(
+        [global_changes, server_pending_updates],
+        PendingCount
+    ),
     NewState = State#state{
         pending_updates=Pending,
-        pending_update_count=sets:size(Pending)
+        pending_update_count=PendingCount
     },
     {noreply, NewState};
 
@@ -157,10 +162,20 @@
 
         spawn(fun() ->
             fabric:update_docs(State#state.dbname, Docs, [])
-        end)
+        end),
+
+        Count = State#state.pending_update_count,
+        couch_stats:increment_counter(
+            [global_changes, db_writes],
+            Count
+        )
     catch error:database_does_not_exist ->
         {noreply, State}
     end,
+    couch_stats:update_gauge(
+        [global_changes, server_pending_updates],
+        0
+    ),
     {noreply, State#state{
         pending_updates=sets:new(),
         pending_update_count=0
@@ -203,5 +218,6 @@
     % global_changes should never encounter a conflict by design
     % but we should record if it happens in case our design isn't
     % quite right.
+    couch_stats:increment_counter([global_changes, event_doc_conflict]),
     {Pos, Rev} = RevInfo#rev_info.rev,
     {Pos, [Rev]}.