More accurate Unicorn#worker_process_count (#74)

More accurate Unicorn#worker_process_count (#74)

When PrometheusExporter::Instrumentation::Unicorn is called from the master process of Unicorn, the previous implementation includes ps process itself. So, it always returns the actual number + 1.

diff --git a/lib/prometheus_exporter/instrumentation/unicorn.rb b/lib/prometheus_exporter/instrumentation/unicorn.rb
index e559b6a..ad93777 100644
--- a/lib/prometheus_exporter/instrumentation/unicorn.rb
+++ b/lib/prometheus_exporter/instrumentation/unicorn.rb
@@ -51,13 +51,13 @@ module PrometheusExporter::Instrumentation
 
     def worker_process_count
       return nil unless File.exist?(@pid_file)
-      pid = File.read(@pid_file)
+      pid = File.read(@pid_file).to_i
 
-      return nil unless pid && pid.to_i > 0
+      return nil unless pid && pid > 0
 
       # find all processes whose parent is the unicorn master
       # but we're actually only interested in the number of processes (= lines of output)
-      result = `ps --no-header -o pid --ppid #{pid}`
+      result = `pgrep -P #{pid} -f unicorn -a`
       result.lines.count
     end

GitHub sha: 5b80d70e

minor style change based on 5b80d70e