]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/munin/files/default/plugins/passenger_requests
Make nftables block various invalid TCP flag combinations
[chef.git] / cookbooks / munin / files / default / plugins / passenger_requests
index f783be974040b67adfd0245fa7e185e8a17c5d97..67dc34367766c8688b1a4323d1daa07f52e12b60 100755 (executable)
@@ -1,29 +1,54 @@
 #!/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_args --base 1000
-graph_category passenger
-graph_title Passenger requests
-graph_vlabel requests / ${graph_period}
-
-requests.label requests
-requests.type DERIVE
-requests.max 1000000
-requests.min 0
-END
-  exit 0
+  puts <<~CONFIG
+    graph_args --base 1000 --lower-limit 0
+    graph_category passenger
+    graph_title Passenger requests
+    graph_vlabel requests / ${graph_period}
+
+    total.label total
+    total.type DERIVE
+    total.max 1000000
+    total.min 0
+  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}.type DERIVE"
+    puts "#{name}.max 1000000"
+    puts "#{name}.min 0"
+  end
 end
 
 def output_values
-  status = `/usr/sbin/passenger-status`
-  unless $?.success?
-    $stderr.puts "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"