]> git.openstreetmap.org Git - chef.git/commitdiff
Rework passenger munin plugins to work with current passenger versions
authorTom Hughes <tom@compton.nu>
Mon, 2 Jul 2018 20:29:03 +0000 (21:29 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 2 Jul 2018 20:29:03 +0000 (21:29 +0100)
cookbooks/munin/files/default/plugins/passenger_processes
cookbooks/munin/files/default/plugins/passenger_queues
cookbooks/munin/files/default/plugins/passenger_requests

index 0611ccc0e7ac4f54a5f2fa3e45b04bdf00a4fa64..eddcf558abe3976ce49179ff037253458688278b 100755 (executable)
@@ -1,6 +1,11 @@
 #!/usr/bin/env ruby
 
 require "English"
+require "rexml/document"
+
+def passenger_status
+  @passenger_status ||= REXML::Document.new(`/usr/sbin/passenger-status --show=xml`)
+end
 
 def output_config
   puts <<~CONFIG
@@ -19,16 +24,19 @@ def output_config
 end
 
 def output_values
-  status = `/usr/sbin/passenger-status`
-  unless $CHILD_STATUS.success?
-    warn "failed executing passenger-status"
-    exit 1
+  active = 0
+  inactive = 0
+
+  passenger_status.get_elements("//process").each do |process|
+    if process.text("sessions").to_i.positive?
+      active += 1
+    else
+      inactive += 1
+    end
   end
-  status =~ /active\s+=\s+(\d+)/
-  puts "active.value #{Regexp.last_match[1]}"
 
-  status =~ /inactive\s+=\s+(\d+)/
-  puts "inactive.value #{Regexp.last_match[1]}"
+  puts "active.value #{active}"
+  puts "inactive.value #{inactive}"
 end
 
 if ARGV[0] == "config"
index 0850ed2735f1deec94546140fcb30f21395edb6a..5e5785796427ebdde798fae51dde9ceba197bde3 100755 (executable)
@@ -1,6 +1,11 @@
 #!/usr/bin/env ruby
 
 require "English"
+require "rexml/document"
+
+def passenger_status
+  @passenger_status ||= REXML::Document.new(`/usr/sbin/passenger-status --show=xml`)
+end
 
 def output_config
   puts <<~CONFIG
@@ -9,18 +14,30 @@ def output_config
     graph_vlabel count
 
     global.label global
+    global.draw AREA
   CONFIG
-  exit 0
+
+  groups = passenger_status.get_elements("//supergroup").map do |supergroup|
+    supergroup.text("name")
+  end
+
+  groups.sort.each do |name|
+    puts "#{name}.label #{name}"
+    puts "#{name}.draw STACK"
+  end
 end
 
 def output_values
-  status = `/usr/sbin/passenger-status`
-  unless $CHILD_STATUS.success?
-    warn "failed executing passenger-status"
-    exit 1
+  global = passenger_status.text("/item/get_wait_list").to_i
+
+  puts "global.value #{global}"
+
+  passenger_status.get_elements("//supergroup").each do |supergroup|
+    name = supergroup.text("name")
+    queue = supergroup.text("get_wait_list").to_i
+
+    puts "#{name}.value #{queue}"
   end
-  status =~ /Requests in top-level queue :\s+(\d+)/
-  puts "global.value #{Regexp.last_match[1]}"
 end
 
 if ARGV[0] == "config"
index dac457e33a8c543f41361cea24eff6368a376270..2e113bf505eb9f14cad6ce8d2fead9f6dfbae5bd 100755 (executable)
@@ -1,6 +1,11 @@
 #!/usr/bin/env ruby
 
 require "English"
+require "rexml/document"
+
+def passenger_status
+  @passenger_status ||= REXML::Document.new(`/usr/sbin/passenger-status --show=xml`)
+end
 
 def output_config
   puts <<~CONFIG
@@ -9,23 +14,41 @@ def output_config
     graph_title Passenger requests
     graph_vlabel requests / ${graph_period}
 
-    requests.label requests
-    requests.type DERIVE
-    requests.max 1000000
-    requests.min 0
+    total.label total
+    total.type DERIVE
+    total.max 1000000
+    total.min 0
   CONFIG
-  exit 0
+
+  groups = passenger_status.get_elements("//supergroup").map do |supergroup|
+    supergroup.text("name")
+  end
+
+  groups.sort.each do |name|
+    puts "#{name}.label #{name}"
+    puts "#{name}.type DERIVE"
+    puts "#{name}.max 1000000"
+    puts "#{name}.min 0"
+  end
 end
 
 def output_values
-  status = `/usr/sbin/passenger-status`
-  unless $CHILD_STATUS.success?
-    warn "failed executing passenger-status"
-    exit 1
-  end
   total_requests = 0
-  status.scan(/Processed: (\d+)/).flatten.each { |count| total_requests += count.to_i }
-  puts "requests.value #{total_requests}"
+
+  passenger_status.get_elements("//supergroup").map do |supergroup|
+    name = supergroup.text("name")
+    requests = 0
+
+    supergroup.get_elements("group/processes/process").each do |process|
+      requests += process.text("processed").to_i
+    end
+
+    total_requests += requests
+
+    puts "#{name}.value #{requests}"
+  end
+
+  puts "total.value #{total_requests}"
 end
 
 if ARGV[0] == "config"