Instantiate read/sent counters before events are processed

Instantiate read/sent counters before events are processed

This will allow me to detect when a container listener fails to proceed, as well as differentiating between the two possible failure modes:

  1. Container listener object is never created; and
  2. Container listener is created, but never started.
diff --git a/lib/mobystash/container.rb b/lib/mobystash/container.rb
index 1f04dcb..b87687b 100644
--- a/lib/mobystash/container.rb
+++ b/lib/mobystash/container.rb
@@ -56,6 +56,13 @@ module Mobystash
 
       @name = (docker_data.info["Name"] || docker_data.info["Names"].first).sub(/\A\//, '')
 
+      if docker_data.info["Config"]["Tty"]
+        @config.log_entries_read_counter.increment({ container_name: @name, container_id: @id, stream: "tty" }, 0)
+      else
+        @config.log_entries_read_counter.increment({ container_name: @name, container_id: @id, stream: "stdout" }, 0)
+        @config.log_entries_read_counter.increment({ container_name: @name, container_id: @id, stream: "stderr" }, 0)
+      end
+
       @capture_logs = true
       @parse_syslog = false
 
@@ -150,6 +157,13 @@ module Mobystash
     end
 
     def process_events(conn)
+      if tty?(conn)
+        @config.log_entries_sent_counter.increment({ container_name: @name, container_id: @id, stream: "tty" }, 0)
+      else
+        @config.log_entries_sent_counter.increment({ container_name: @name, container_id: @id, stream: "stdout" }, 0)
+        @config.log_entries_sent_counter.increment({ container_name: @name, container_id: @id, stream: "stderr" }, 0)
+      end
+
       if @capture_logs
         begin
           unless Docker::Container.get(@id, {}, conn).info.fetch("State", {}).fetch("Running")

GitHub sha: a2e6ddc9