pagespeed_grabber 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +32 -0
- data/Rakefile +25 -0
- data/Readme.md +23 -0
- data/VERSION +1 -0
- data/lib/pagespeed_grabber.rb +46 -0
- data/munin.rb +25 -0
- data/pagespeed_grabber.gemspec +48 -0
- data/spec/pagespeed_grabber_spec.rb +8 -0
- metadata +102 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
fastercsv (1.5.4)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
mechanize (1.0.0)
|
12
|
+
nokogiri (>= 1.2.1)
|
13
|
+
nokogiri (1.4.4)
|
14
|
+
rake (0.8.7)
|
15
|
+
rspec (2.5.0)
|
16
|
+
rspec-core (~> 2.5.0)
|
17
|
+
rspec-expectations (~> 2.5.0)
|
18
|
+
rspec-mocks (~> 2.5.0)
|
19
|
+
rspec-core (2.5.1)
|
20
|
+
rspec-expectations (2.5.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.5.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
fastercsv
|
29
|
+
jeweler
|
30
|
+
mechanize
|
31
|
+
rake
|
32
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
task :default do
|
2
|
+
sh "rspec spec/"
|
3
|
+
end
|
4
|
+
|
5
|
+
task :headers do
|
6
|
+
require File.expand_path('lib/webpagetest_grabber')
|
7
|
+
csv = `curl http://www.webpagetest.org/result/110316_DA_5TFD/110316_DA_5TFD_google.com_page_data.csv`
|
8
|
+
data = PagespeedGrabber.csv_to_array(csv).first.keys
|
9
|
+
puts data.inspect
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
gem.name = 'pagespeed_grabber'
|
16
|
+
gem.summary = "Grab pagespeed results from external services to use them in e.g. munin."
|
17
|
+
gem.email = "michael@grosser.it"
|
18
|
+
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
19
|
+
gem.authors = ["Michael Grosser"]
|
20
|
+
end
|
21
|
+
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
25
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Grab pagespeed results from external services to use them in e.g. munin.<br/>
|
2
|
+
Currently only support webpagetest.org, which is not very reliable and sometimes slow.
|
3
|
+
|
4
|
+
Not ready for production just a toy project.
|
5
|
+
|
6
|
+
data = PagespeedGrabber.fetch('google.com', :from => 'webpagetest', :timeout => 200)
|
7
|
+
|
8
|
+
### Munin
|
9
|
+
`munin.rb` can be moved into munin/plugins and renamed to e.g. webpagetest_google.com to aggregate results.
|
10
|
+
|
11
|
+
TODO
|
12
|
+
====
|
13
|
+
- add other services
|
14
|
+
- make less hacky/use official apis
|
15
|
+
- generate initial AND repeated graph
|
16
|
+
- find a reliable service
|
17
|
+
- parse .har file from e.g. loads.in
|
18
|
+
|
19
|
+
Authors
|
20
|
+
=======
|
21
|
+
[Michael Grosser](http://grosser.it)<br/>
|
22
|
+
michael@grosser.it<br/>
|
23
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize'
|
3
|
+
require 'faster_csv'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
module PagespeedGrabber
|
7
|
+
URL = 'http://www.webpagetest.org'
|
8
|
+
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
9
|
+
DEFAULT_TIMEOUT = 100
|
10
|
+
TIME_BETWEEN_TRIES = 10
|
11
|
+
CSV_LINK = 'Raw page data'
|
12
|
+
HEADERS = ["Load Time (ms)", "Other Responses (Doc)", "Connections", "Minify Savings", "Experimental", "IP Address", "ETag Score", "GZIP Score", "DNS Lookups", "Event Name", "Not Found", "Segments Transmitted", "Keep-Alive Score", "Time", "Not Modified", "Cookie Score", "Measurement Type", "Gzip Savings", "Time to Base Page Complete (ms)", "One CDN Score", "OK Responses", "Error Code", "unused", "Requests", "Other Responses", "Includes Object Data", "Minify Total Bytes", "Flagged Requests", "AFT (ms)", "Packet Loss (out)", "Compression Score", "URL", "OK Responses (Doc)", "Combine Score", "Base Page Result", "Doc Complete Time (ms)", "Redirects (Doc)", "Pagetest Build", "Minify Score", "Time to Start Render (ms)", "Cache Score", "Base Page Redirects", "Bytes Out (Doc)", "Descriptor", "Dialer ID", "Connection Type", "Activity Time(ms)", "Time to First Byte (ms)", "Date", "Not Found (Doc)", "Redirects", "Not Modified (Doc)", "Event GUID", "Event URL", "Requests (Doc)", "Bytes In (Doc)", "Time to DOM Element (ms)", "Static CDN Score", "Optimization Checked", "Image Savings", "Connections (Doc)", "Flagged Connections", "Max Simultaneous Flagged Connections", "Cached", "Gzip Total Bytes", "Bytes Out", "Bytes In", "DNS Lookups (Doc)", "Segments Retransmitted", "DOCTYPE Score", "Image Total Bytes", "Host", "Lab ID"]
|
13
|
+
|
14
|
+
def self.fetch(test_url, options={})
|
15
|
+
Timeout.timeout(options[:timeout]||DEFAULT_TIMEOUT) do
|
16
|
+
csv_to_array(download_csv(test_url))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.download_csv(test_url)
|
21
|
+
agent = Mechanize.new
|
22
|
+
page = agent.get(URL)
|
23
|
+
form = page.forms.first
|
24
|
+
form.field_with('url').value = test_url
|
25
|
+
page = form.submit
|
26
|
+
|
27
|
+
url = page.uri.to_s
|
28
|
+
link = nil
|
29
|
+
|
30
|
+
loop do
|
31
|
+
sleep TIME_BETWEEN_TRIES
|
32
|
+
page = agent.get(url)
|
33
|
+
break if link = page.link_with(:text => CSV_LINK)
|
34
|
+
end
|
35
|
+
|
36
|
+
agent.get(URL + link.href).body
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.csv_to_array(csv)
|
40
|
+
data = []
|
41
|
+
FasterCSV.parse(csv, :headers=>true) do |row|
|
42
|
+
data << row.to_hash
|
43
|
+
end
|
44
|
+
data
|
45
|
+
end
|
46
|
+
end
|
data/munin.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pagespeed_grabber'
|
4
|
+
|
5
|
+
test_url = File.dirname(__FILE__).split('_',2).last
|
6
|
+
|
7
|
+
def clean_name(name)
|
8
|
+
name.gsub(/[ \(\)]/,'_').downcase
|
9
|
+
end
|
10
|
+
|
11
|
+
if ARGV[0].to_s == 'config'
|
12
|
+
puts "graph_title #{test_url} Webpagetest\n";
|
13
|
+
puts "graph_vlabel number\n";
|
14
|
+
puts "graph_scale no\n";
|
15
|
+
puts "graph_category other\n";
|
16
|
+
|
17
|
+
PagespeedGrabber::HEADERS.each do |header|
|
18
|
+
puts "#{clean_name(header)}.label #{header}\n"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
initial, repeated = PagespeedGrabber.fetch(test_url)
|
22
|
+
initial.each do |header, value|
|
23
|
+
puts "#{clean_name(header)}.value #{value}"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pagespeed_grabber}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Grosser"]
|
12
|
+
s.date = %q{2011-03-17}
|
13
|
+
s.email = %q{michael@grosser.it}
|
14
|
+
s.files = [
|
15
|
+
"Gemfile",
|
16
|
+
"Gemfile.lock",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"lib/pagespeed_grabber.rb",
|
21
|
+
"munin.rb",
|
22
|
+
"pagespeed_grabber.gemspec",
|
23
|
+
"spec/pagespeed_grabber_spec.rb"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/grosser/pagespeed_grabber}
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.rubygems_version = %q{1.4.2}
|
28
|
+
s.summary = %q{Grab pagespeed results from external services to use them in e.g. munin.}
|
29
|
+
s.test_files = [
|
30
|
+
"spec/pagespeed_grabber_spec.rb"
|
31
|
+
]
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
s.add_runtime_dependency(%q<mechanize>, [">= 0"])
|
38
|
+
s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
41
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<mechanize>, [">= 0"])
|
45
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('lib/pagespeed_grabber')
|
2
|
+
|
3
|
+
describe PagespeedGrabber do
|
4
|
+
it "can fetch results for an url" do
|
5
|
+
initial, repeated = PagespeedGrabber.fetch('google.com')
|
6
|
+
initial['Load Time (ms)'].to_i.should > repeated['Load Time (ms)'].to_i
|
7
|
+
end
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pagespeed_grabber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Grosser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-17 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
requirement: *id001
|
33
|
+
name: mechanize
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
requirement: *id002
|
47
|
+
name: fastercsv
|
48
|
+
prerelease: false
|
49
|
+
description:
|
50
|
+
email: michael@grosser.it
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- Gemfile
|
59
|
+
- Gemfile.lock
|
60
|
+
- Rakefile
|
61
|
+
- Readme.md
|
62
|
+
- VERSION
|
63
|
+
- lib/pagespeed_grabber.rb
|
64
|
+
- munin.rb
|
65
|
+
- pagespeed_grabber.gemspec
|
66
|
+
- spec/pagespeed_grabber_spec.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/grosser/pagespeed_grabber
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.4.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Grab pagespeed results from external services to use them in e.g. munin.
|
101
|
+
test_files:
|
102
|
+
- spec/pagespeed_grabber_spec.rb
|