Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add page speed score for configured sites.

  • Loading branch information...
commit 832bb1aaeeba0e4d3ff9db1cd1f3787a73688cb3 1 parent eccf5d1
Tom authored
View
7 Rakefile
@@ -14,6 +14,13 @@ namespace :db do
end
end
+namespace :page_speed do
+ desc "Fetch page speed results for configured projects"
+ task :fetch_results do
+ PageSpeed.fetch_results
+ end
+end
+
desc "Run all specs"
RSpec::Core::RakeTask.new('spec') do |t|
t.pattern = 'spec/**/*.rb'
View
6 config.sample.rb
@@ -61,7 +61,8 @@
:id => "an integer"
},
:slimtimer => {
- :ids => ["tri", "tro"]
+ :ids => ["tri", "tro"],
+ :task_prefix => "i:tri system"
},
:chartbeat_url => "example.com"
}
@@ -83,4 +84,7 @@
SLIMTIMER_GOD = "email@example.com"
CHARTBEAT_APIKEY = "key"
+
+ GOOGLE_PAGE_SPEED_URL = "https://www.googleapis.com/pagespeedonline/v1/runPagespeed"
+ GOOGLE_SIMPLE_APIKEY = "key"
end
View
7 dashboard.rb
@@ -2,7 +2,7 @@
open-uri hpricot json librmpd yahoo-weather httparty active_support/all ].each { |lib| require lib }
%w[ ext/fixnum ext/array mpd_proxy ].each { |lib| require "lib/#{lib}" }
require 'config'
-%w[ ci pivotal nagios stats pivotal_slimtimer_updater].each { |lib| require "lib/#{lib}" }
+%w[ ci pivotal nagios stats pivotal_slimtimer_updater page_speed ].each { |lib| require "lib/#{lib}" }
%w[ project slimtimer_task slimtimer_user time_entry report time_report summary_report story shepherd
].each { |model| require "models/#{model}" }
@@ -52,8 +52,9 @@ def height_for(val, max)
@projects = PROJECTS.reject { |name, attributes| attributes[:hidden] }
@projects.each do |name, attributes|
- attributes[:activity] = Stats.status_for(name)
- attributes[:shepherd] = Project.find(name).shepherd
+ attributes[:activity] = Stats.status_for(name)
+ attributes[:shepherd] = Project.find(name).shepherd
+ attributes[:page_speed_score] = PageSpeed.load_results[name]
end
haml :index
View
29 lib/page_speed.rb
@@ -0,0 +1,29 @@
+class PageSpeed
+ include HTTParty
+
+ class << self
+ def results_file
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp", "page_speed_scores.json"))
+ end
+
+ def fetch_results
+ scores = {}
+ projects = Project.all.select { |p| !p.attributes[:chartbeat_url].blank? }
+
+ projects.each do |project|
+ url = project.attributes[:chartbeat_url]
+ doc = get("#{GOOGLE_PAGE_SPEED_URL}?url=http://#{url}&key=#{GOOGLE_SIMPLE_APIKEY}")
+
+ scores[project.id] = doc["score"]
+ end
+
+ File.open(results_file, "w+") do |f|
+ f.puts scores.to_json
+ end
+ end
+
+ def load_results
+ @results ||= JSON.parse(File.read(results_file)).to_hash
+ end
+ end
+end
View
3  public/stylesheets/main.css
@@ -148,6 +148,9 @@ h1 {
margin: 0 5px;
font-weight: normal;
}
+.status .info .attribute.speed {
+ margin-top: -2px;
+}
.status .info .attribute.right {
float: right;
}
View
4 views/index.haml
@@ -15,7 +15,9 @@
.points= attributes[:shepherd]
.info
.summary
- .attribute.health.rcov
+ .attribute.speed
+ - if attributes[:page_speed_score]
+ %img{ :src => "https://chart.googleapis.com/chart?cht=gom&chd=t:#{attributes[:page_speed_score]}&chs=40x18&chf=bg,s,65432100" }
.attribute.stats.right= haml :stats, :locals => { :stats => attributes[:activity], :max => max_activity_across_projects(@projects) }, :layout => false
#second.column
%h1 Systems

0 comments on commit 832bb1a

Please sign in to comment.
Something went wrong with that request. Please try again.