Skip to content

Instantly share code, notes, and snippets.

@tomlobato
Last active January 11, 2018 18:49
Show Gist options
  • Save tomlobato/444e0454f8b2da09aaee93e578010c56 to your computer and use it in GitHub Desktop.
Save tomlobato/444e0454f8b2da09aaee93e578010c56 to your computer and use it in GitHub Desktop.

Revisions

  1. tomlobato revised this gist Jan 11, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion passenger_status.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ def config
    graph_category #{graph_category}
    graph_title Passenger stats
    graph_vlabel count
    graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
    graph_args --base 1000 -l 0
    graph_info Passenger stats - railsdoctors.com
    max_pool_size.label max pool size
    @@ -30,6 +30,7 @@ def config
    cpu.label %cpu /10
    memory.label memory /100
    CONFIG
    # --upper-limit #{upper_limit}
    exit 0
    end

  2. tomlobato renamed this gist Jan 11, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. tomlobato created this gist Jan 11, 2018.
    7 changes: 7 additions & 0 deletions conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    [passenger_*]
    user root
    command /root/.rbenv/shims/ruby %c
    env.passenger_status /root/.rbenv/shims/passenger-status
    env.passenger_memory_stats /root/.rbenv/shims/passenger-memory-stats
    env.graph_category Passenger
    env.PASSENGER_INSTANCE_REGISTRY_DIR /tmp/aptmp
    77 changes: 77 additions & 0 deletions passenger_status.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    #!/bin/env ruby
    # encoding: utf-8
    module Munin
    class PassengerStatus < RequestLogAnalyzerPlugin
    def ensure_configuration
    require_passenger_status
    super
    end

    def config
    status = `#{passenger_status}`

    status =~ /max\s+=\s+(\d+)/
    upper_limit = $1 || 150

    puts <<-CONFIG
    graph_category #{graph_category}
    graph_title Passenger stats
    graph_vlabel count
    graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
    graph_info Passenger stats - railsdoctors.com
    max_pool_size.label max pool size
    app_groups.label app groups
    processes.label processes
    requests_in_top_level_queue.label requests in top level queue
    requests_in_queue.label requests in queue
    sessions.label sessions
    processed.label processed /10000
    cpu.label %cpu /10
    memory.label memory /100
    CONFIG
    exit 0
    end

    def str_list str
    str
    .split(/\n/)
    .map(&:strip)
    .reject(&:empty?)
    end

    def run
    status = run_command(passenger_status, debug)

    str_list("
    Max pool size
    App groups
    Processes
    Requests in top-level queue
    ").each do |str|
    key = str.downcase.gsub(/(\s|-)+/, '_')
    status =~ /#{str}\s*:\s*(\d+)/i
    puts "#{key}.value #{$1}"
    end

    str_list("
    Requests in queue
    Sessions
    Processed /10000
    CPU /10
    Memory /100
    ").each do |str|
    divisor = 1
    if str =~ /^(.*?)\s*\/\s*(\d+)\s*$/
    str = $1
    divisor = $2.to_f
    end
    key = str.downcase.gsub(/\s+/, '_')
    total = 0
    status.scan(/#{str}\s*:\s*(\d+)/).flatten.each { |count| total += count.to_i }
    puts "#{key}.value #{total/divisor}"
    end

    end
    end
    end