Navigation Menu

Skip to content

Commit

Permalink
more detailed graphs and caching
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Mar 22, 2011
1 parent bc07f5d commit 12e02b4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 29 deletions.
25 changes: 15 additions & 10 deletions Readme.md
Expand Up @@ -5,24 +5,29 @@ Not ready for production just a toy project.

data = PagespeedGrabber.fetch('google.com', :from => 'webpagetest', :timeout => 200)

### Munin
move [munin.rb](https://github.com/grosser/pagespeed_grabber/raw/master/munin.rb) into munin/plugins and renamed to e.g. webpagetest_google.com to aggregate results.
# Munin

### Download
sudo su

gem install pagespeed_grabber
curl https://github.com/grosser/pagespeed_grabber/raw/master/munin.rb > /usr/shared/munin/plugins/pagespeed_grabber
chmod +x /usr/shared/munin/plugins/pagespeed_grabber
curl https://github.com/grosser/pagespeed_grabber/raw/master/munin.rb > /usr/share/munin/plugins/pagespeed_grabber
chmod +x /usr/share/munin/plugins/pagespeed_grabber

ls -s /usr/shared/munin/plugins/pagespeed_grabber /etc/munin/plugins/webpagetest_google.com
### Add data cron and run it once
*/5 * * * * /usr/share/munin/plugins/pagespeed_grabber cache webpagetest google.com

./etc/munin/plugins/webpagetest_google.com config # check config works
./etc/munin/plugins/webpagetest_google.com # check values are returned
### Add plugins for time, data, score, connections graphs
ln -s /usr/share/munin/plugins/pagespeed_grabber /etc/munin/plugins/webpagetest_time_de.dawanda.com
ln -s /usr/share/munin/plugins/pagespeed_grabber /etc/munin/plugins/webpagetest_data_de.dawanda.com
ln -s /usr/share/munin/plugins/pagespeed_grabber /etc/munin/plugins/webpagetest_score_de.dawanda.com
ln -s /usr/share/munin/plugins/pagespeed_grabber /etc/munin/plugins/webpagetest_connections_de.dawanda.com

# insert into /etc/munin/plugin-conf.d/munin-node
[webpagetest_google.com]
timeout 100
### Check plugins work
./etc/munin/plugins/webpagetest_time_google.com config # config works
./etc/munin/plugins/webpagetest_time_google.com # values are returned

### Restart
/etc/init.d/munin-node.restart


Expand Down
74 changes: 55 additions & 19 deletions munin.rb
@@ -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

0 comments on commit 12e02b4

Please sign in to comment.