]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/munin/files/default/plugins/passenger_queues
Anchor passenger graphs to zero
[chef.git] / cookbooks / munin / files / default / plugins / passenger_queues
index a7060fd665c9c5ed9159e2ddcd8bdd57dbddb2a2..a5467660c9f2867b3e7f4cbba5a526d23ef3ebf0 100755 (executable)
@@ -1,24 +1,44 @@
 #!/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 <<-END
-graph_category passenger
-graph_title Passenger queues
-graph_vlabel count
-
-global.label global
-END
-  exit 0
+  puts <<~CONFIG
+    graph_args --lower-limit 0
+    graph_category passenger
+    graph_title Passenger queues
+    graph_vlabel count
+
+    global.label global
+    global.draw AREA
+  CONFIG
+
+  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?
-    $stderr.puts "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 =~ /Waiting on global queue:\s+(\d+)/
-  puts "global.value #{Regexp.last_match[1]}"
 end
 
 if ARGV[0] == "config"