Last active
March 15, 2019 11:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
to get the 10 most CPU intensive requests currently being served.