Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
29 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,68 @@ | ||
#!/usr/local/bin/ruby | ||
require 'rubygems' | ||
require 'yaml' | ||
require 'pagespeed_grabber' | ||
|
||
test_url = File.basename(__FILE__).split('_',2).last | ||
|
||
def clean_name(name) | ||
name.gsub(/[ \(\)]/,'_').downcase | ||
end | ||
|
||
not_reportable = [ | ||
'Date', 'Descriptor', 'Connection Type', 'Event GUID', 'Event Name', 'Event URL', 'Experimental', 'Host', 'IP Address', 'Lab ID', | ||
'Includes Object Data', 'Max Simultaneous Flagged Connections', 'Pagetest Build', 'Time', 'URL', 'unused', 'Keep-Alive Score' | ||
] | ||
headers = (PagespeedGrabber::HEADERS - not_reportable).sort | ||
def temp_file(source, url) | ||
"/tmp/munin-cache-#{source}-#{url}" | ||
end | ||
|
||
if ARGV[0].to_s == 'config' | ||
puts "graph_title #{test_url} Webpagetest\n"; | ||
puts "graph_vlabel number\n"; | ||
puts "graph_scale no\n"; | ||
puts "graph_category other\n"; | ||
def select_headers(headers, type) | ||
useless = [ | ||
'Bytes In', 'Bytes Out', 'Connections', 'DNS Lookups', 'Flagged Connections', 'Flagged Requests', | ||
'Max Simultaneous Flagged Connections', 'OK Responses', 'Other Responses', 'Other Responses (Doc)', 'Requests', 'Time' | ||
] | ||
|
||
headers.each do |header| | ||
puts "#{clean_name(header)}.label #{header}\n" | ||
end | ||
selector = { | ||
'time' => /Time/, | ||
'data' => /Bytes|Savings/, | ||
'connections' => /DNS|Responses|Requests|Segments|Connections|Packet Loss/, | ||
'score' => /Score/ | ||
}[type] || raise('Unknown type') | ||
|
||
(headers - useless).grep(selector).sort | ||
end | ||
|
||
def is_numeric?(value) | ||
value.to_s =~ /^-?[\d]+(\.\d+)?$/ | ||
end | ||
|
||
if ARGV[0] == 'cache' | ||
source = ARGV[1] || raise('source needed') | ||
url = ARGV[2] || raise('url needed') | ||
|
||
data = PagespeedGrabber.fetch(url, :from => source) | ||
File.open(temp_file(source, url), 'w'){|f| f.write(data.to_yaml) } | ||
else | ||
initial, repeated = PagespeedGrabber.fetch(test_url) | ||
initial.sort.each do |header, value| | ||
next unless headers.include?(header) | ||
puts "#{clean_name(header)}.value #{value}" if value.to_s =~ /^-?[\d]+(\.\d+)?$/ | ||
source, type, url = File.basename(__FILE__).split('_',3) | ||
data = YAML.load_file(temp_file(source, url)) | ||
headers = select_headers(data.first.keys, type) | ||
|
||
if ARGV[0] == 'config' | ||
label = { | ||
'data' => 'Bytes', | ||
'time' => 'ms', | ||
'score' => '%', | ||
'connections' => 'number' | ||
}[type] | ||
|
||
puts "graph_title #{url} #{type} by #{source}" | ||
puts "graph_vlabel #{label}" | ||
puts "graph_scale no" | ||
puts "graph_category pagespeed" | ||
|
||
headers.each do |header| | ||
puts "#{clean_name(header)}.label #{header}" | ||
end | ||
else | ||
initial, repeated = data | ||
initial.sort.each do |header, value| | ||
next unless headers.include?(header) and is_numeric?(value) | ||
puts "#{clean_name(header)}.value #{value}" | ||
end | ||
end | ||
end |