Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

lillesvin commented Mar 15, 2019

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
You can’t perform that action at this time.