Module: MuninPassenger::Collect

Defined in:
lib/munin_passenger/collect.rb

Class Method Summary collapse

Class Method Details

.get_group_stats(doc) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/munin_passenger/collect.rb', line 15

def self.get_group_stats(doc)
  ret = []
  doc.xpath('//info/supergroups/supergroup').each do |x_supergroup|
    x_supergroup.xpath('./group').each do |x_group|
      g = OpenStruct.new
      g.name = x_group.xpath('name').first.text
      g.queue = x_group.xpath('get_wait_list_size').first.text
      ret << g
    end
  end
  ret
end

.get_ps_stats(doc) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/munin_passenger/collect.rb', line 28

def self.get_ps_stats(doc)
  ret = []
  now = Time.now
  doc.xpath('//info/supergroups/supergroup').each do |x_supergroup|
    x_supergroup.xpath('./group').each do |x_group|
      x_group.xpath('./processes/process').each do |x_ps|
        ps = OpenStruct.new
        ps.pid         = x_ps.xpath('pid').first.text
        ps.sessions    = x_ps.xpath('sessions').first.text.to_i
        ps.last_used   = (now - Time.at(x_ps.xpath('last_used').first.text.to_i / 1000 / 1000).to_i).to_i # in seconds
        ps.ram         = x_ps.xpath('real_memory').first.text.to_i   # in KB
        ps.cpu         = x_ps.xpath('cpu').first.text.to_i           # in %
        ps.uptime      = (now - Time.at(x_ps.xpath('spawn_start_time').first.text.to_i / 1000 / 1000).to_i).to_i # in seconds
        ps.processed   = x_ps.xpath('processed').first.text.to_i     # in requests
        ret << ps
      end
    end
  end
  ret
end

.parse_stats(f) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/munin_passenger/collect.rb', line 7

def self.parse_stats(f)
  Nokogiri::XML(f) do |config|
    config.strict.
           noblanks.  # Exclude blank nodes
           nonet      # Don't make any network connections
  end
end

.run_statusObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/munin_passenger/collect.rb', line 49

def self.run_status
  dir = if ENV['PASSENGER_ROOT']
          "#{ENV['PASSENGER_ROOT']}/"
        else
          ''
        end

  sudo = if ENV['WITHOUT_SUDO']
           ''
         else
           'sudo '
         end

  status = `#{sudo}#{dir}passenger-status --show=xml`
  if not $?.success?
    $stderr.puts 'Error running passenger-status'
    exit 1
  end
  status
end