Permalink
Browse files

Support for parsing mod_pagespeed tags when they are embedded inside …

…pre tags
  • Loading branch information...
1 parent ff8f822 commit 59c593efed6e8276c814a696fd532d56d65da889 @itsderek23 itsderek23 committed Oct 3, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -14,9 +14,7 @@ def build_report
return error("Please provide a url to mod_pagespeed_statistics","By default, the statistics are served from http://localhost/mod_pagespeed_statistics.")
end
body = open(option(:url))
-
- stats=YAML.load(body)
-
+ stats = load_stats(body.read)
# each of these stats is from startup. calculate the rate.
stats.each do |name,value|
next if !TRACKED.include?(name)
@@ -45,4 +43,16 @@ def build_report
javascript_total_blocks
page_load_count
)
+
+ private
+
+ # More recent versions of mod_pagespeed return an HTML-like doc. Stats are in PRE tags.
+ def load_stats(doc)
+ yaml=if doc.include?('<pre>')
+ doc.match( /<pre>(.+)<\/pre>/m)[1]
+ else
+ doc
+ end
+ YAML::load(yaml)
+ end
end
@@ -7,6 +7,7 @@ class ModPagespeedMonitoringTest < Test::Unit::TestCase
def setup
@options=parse_defaults("mod_pagespeed_monitoring")
@stats = File.read(File.dirname(__FILE__)+"/fixtures/statistics.txt")
+ @stats_with_histograms = File.read(File.dirname(__FILE__)+"/fixtures/stats_with_histograms.txt")
end
def teardown
@@ -37,6 +38,32 @@ def test_initial_runs
end # Timecop
end
+ # Appears that newer versions of mod_pagespeed uses an HTML version of the stats page. Stats are embedded
+ # inside PRE tags.
+ def test_run_with_histograms
+ uri=@options['url']
+ FakeWeb.register_uri(:get, uri, :body => @stats_with_histograms)
+ @plugin=ModPagespeedMonitoring.new(nil,{},@options)
+
+ time = Time.now
+ Timecop.travel(time-60*10) do
+ # no reports on initial run
+ res = @plugin.run()
+ assert res[:reports].empty?
+ assert res[:memory].size <= 20
+ res[:memory].each do |k,v|
+ assert ModPagespeedMonitoring::TRACKED.include?(k.sub('_counter_',''))
+ end
+
+ Timecop.travel(time) do
+ @plugin=ModPagespeedMonitoring.new(time-60*10,res[:memory],@options)
+ # reports on subsequent runs
+ res = @plugin.run()
+ assert_equal 7, res[:reports].size # has a subset of reports
+ end # now
+ end # Timecop
+ end
+
def test_connection_refused
@plugin=ModPagespeedMonitoring.new(nil,{},@options)
res = @plugin.run()

0 comments on commit 59c593e

Please sign in to comment.