Rework passenger munin plugins to work with current passenger versions
[chef.git] / cookbooks / munin / files / default / plugins / passenger_processes
1 #!/usr/bin/env ruby
2
3 require "English"
4 require "rexml/document"
5
6 def passenger_status
7   @passenger_status ||= REXML::Document.new(`/usr/sbin/passenger-status --show=xml`)
8 end
9
10 def output_config
11   puts <<~CONFIG
12     graph_category passenger
13     graph_title Passenger processes
14     graph_order active inactive
15     graph_vlabel processes
16     graph_total total
17
18     active.label busy servers
19     active.draw AREA
20     inactive.label idle servers
21     inactive.draw STACK
22   CONFIG
23   exit 0
24 end
25
26 def output_values
27   active = 0
28   inactive = 0
29
30   passenger_status.get_elements("//process").each do |process|
31     if process.text("sessions").to_i.positive?
32       active += 1
33     else
34       inactive += 1
35     end
36   end
37
38   puts "active.value #{active}"
39   puts "inactive.value #{inactive}"
40 end
41
42 if ARGV[0] == "config"
43   output_config
44 else
45   output_values
46 end