Skip to content

Instantly share code, notes, and snippets.

@lillesvin
Last active March 15, 2019 11:08
Show Gist options
  • Save lillesvin/6d8985c508e3ed6f2b54a3a72fd6d35b to your computer and use it in GitHub Desktop.
Save lillesvin/6d8985c508e3ed6f2b54a3a72fd6d35b to your computer and use it in GitHub Desktop.
Parses Apache Extended Server Status pages and converts them to CSV. Great in combination with https://github.com/BurntSushi/xsv
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'csv'
if ARGV.length < 1
puts "Error: Please supply a URL pointing to an Apache Extended Server Status page"
exit
end
page = Nokogiri::HTML(open(ARGV.first))
table = page.css('table').first
csv_options = {
headers: true
}
out = CSV.generate(csv_options) do |csv|
csv << table.css('tr').first.css('th').map {|h| h.text.strip}
table.css('tr')[1..-1].each do |row|
csv << row.css('td').map {|r| r.text.strip}
end
end
puts out
@lillesvin
Copy link
Author

Example:

csvize-server-status.rb "<URL of status page>" | xsv sort -s CPU -NR | xsv slice -l 10 | xsv table

to get the 10 most CPU intensive requests currently being served.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment