Skip to content

Instantly share code, notes, and snippets.

@plasticine
Created August 27, 2012 04:20
Show Gist options
  • Save plasticine/3485504 to your computer and use it in GitHub Desktop.
Save plasticine/3485504 to your computer and use it in GitHub Desktop.
CI Frontend Stats
require 'chrome_debugger'
require 'librato/metrics'
LIBRATO_PREFIX = "tc.frontend"
LIBRATO_USER = ENV["LIBRATO_USER"]
LIBRATO_KEY = ENV["LIBRATO_KEY"]
PAGES = {
google: 'http://google.com/',
yahoo: 'http://yahoo.com/'
nytimes: 'http://nytimes.com'
}
Librato::Metrics.authenticate(LIBRATO_USER, LIBRATO_KEY)
librato_queue = Librato::Metrics::Queue.new
PAGES.each do |name, url|
ChromeDebugger::Client.open do |chrome|
document = chrome.load_url(url)
{
requests: document.request_count,
onload_event: document.onload_event,
dom_content_event: document.dom_content_event,
document_payload: document.encoded_bytes("Document"),
script_payload: document.encoded_bytes("Script"),
image_payload: document.encoded_bytes("Image"),
stylesheet_payload: document.encoded_bytes("Stylesheet"),
other_payload: document.encoded_bytes("Other"),
document_uncompressed_payload: document.bytes("Document"),
script_uncompressed_payload: document.bytes("Script"),
image_uncompressed_payload: document.bytes("Image"),
stylesheet_uncompressed_payload: document.bytes("Stylesheet"),
other_uncompressed_payload: document.bytes("Other"),
script_count: document.request_count_by_resource("Script"),
image_count: document.request_count_by_resource("Image"),
stylesheet_count: document.request_count_by_resource("Stylesheet")
}.each {|key, value|
puts "#{LIBRATO_PREFIX}.#{name}.#{key}: #{value}"
}.each { |key, value|
librato_queue.add("#{LIBRATO_PREFIX}.#{name}.#{key}" => value)
}
end
end
librato_queue.submit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment