Skip to content

Instantly share code, notes, and snippets.

@hectorcorrea
Last active September 4, 2018 13:41
Show Gist options
  • Save hectorcorrea/c302d24264ea9ca6cfd39231f0571503 to your computer and use it in GitHub Desktop.
Save hectorcorrea/c302d24264ea9ca6cfd39231f0571503 to your computer and use it in GitHub Desktop.
Creates a tab delimited list from the passenger status log file.
# Parses a file with the output of `passenger-status` and outputs a
# tab delimited list with the date and number of requests in queue
# that `passenger-status` reported.
#
# The file `passenger_status.log` is created with via a cron job that
# runs every X minutes as follows:
#
# /path/to/.gem/gems/passenger-5.1.12/bin/passenger-status >> ./logs/passenger_status.log
#
#
require "date"
log_file = "passenger_status.log"
excel_date = true
spikes_only = false
def date_from_line(line, excel_date)
index = line.index(":")
return nil if index == nil
date_as_text = line[index+2..-1].strip # Thu Aug 30 14:00:01 -0400 2018
datetime = DateTime.parse(date_as_text).to_s # 2018-08-30T14:00:01-04:00
if excel_date
return datetime[0..9] + " " + datetime[11..15] # 2018-08-30 14:00
end
datetime
end
def count_from_line(line)
return line.gsub("Requests in queue:", "").to_i
end
puts "timestamp\trequest_in_queue"
date = "N/A"
File.readlines(log_file).each do |line|
if line.start_with?("Date ")
date = date_from_line(line, excel_date)
elsif line.include?("Requests in queue:")
if spikes_only
next if line.include?("Requests in queue: 0")
end
request_count = count_from_line(line)
puts "\"#{date}\"\t#{request_count}"
end
end
Version : 5.1.12
Date : Tue Sep 04 09:10:01 -0400 2018
Instance: xl76F8DL (Apache/2.2.15 (Unix) DAV/2 Phusion_Passenger/5.1.12)
----------- General information -----------
Max pool size : 6
App groups : 1
Processes : 5
Requests in top-level queue : 0
----------- Application groups -----------
/your/app/path/goes/here:
App root: /your/app/path/goes/here
Requests in queue: 0
* PID: 22655 Sessions: 0 Processed: 47987 Uptime: 2d 5h 20m 52s
CPU: 0% Memory : 246M Last used: 6s ag
* PID: 60607 Sessions: 0 Processed: 78 Uptime: 25m 53s
CPU: 0% Memory : 141M Last used: 21s ago
* PID: 61272 Sessions: 0 Processed: 45 Uptime: 24m 1s
CPU: 0% Memory : 112M Last used: 21s ago
* PID: 61712 Sessions: 0 Processed: 9 Uptime: 18m 34s
CPU: 0% Memory : 108M Last used: 3m 3s ago
* PID: 63593 Sessions: 0 Processed: 0 Uptime: 3m 1s
CPU: 0% Memory : 24M Last used: 3m 1s ago
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment