#!/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 graph_args --lower-limit 0 graph_category passenger graph_title Passenger processes graph_order active inactive graph_vlabel processes graph_total total active.label busy servers active.draw AREA inactive.label idle servers inactive.draw STACK CONFIG exit 0 end def output_values 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 puts "active.value #{active}" puts "inactive.value #{inactive}" end if ARGV[0] == "config" output_config else output_values end