Skip to content

Instantly share code, notes, and snippets.

@sizief
Last active November 13, 2019 17:26
Show Gist options
  • Save sizief/c6d022568029a842fa0c1f0115867884 to your computer and use it in GitHub Desktop.
Save sizief/c6d022568029a842fa0c1f0115867884 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# see here for more info https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/
# uncomment --output-path tosave output
# to send data periodically only one run `wheneverize .` and then
# `whenever --update-crontab` You can set time period changin `config/schedule.rb`
require 'json'
require 'rubygems'
require 'dogapi'
require 'dotenv'
Dotenv.load
targets = [
{
url: 'https://xxx.com/blog/',
name: 'blog',
},
{
url: 'https://xxx.com',
name: 'Home',
}
]
test_conditions = [
{
name: 'fast',
flags: '--emulated-form-factor=none --throttling-method=provided'
},
{
name: 'slow',
flags: nil
}
]
dog = Dogapi::Client.new(ENV['API_KEY'], ENV['APP_KEY'])
#today = Time.now.strftime("%d-%m-%Y")
#Dir.mkdir(today) unless File.exists?(today)
Dir.mkdir('config') unless File.exists?('config')
targets.each do |target|
# file_path = "./#{today}/#{target[:name]}.json"
test_conditions.each do |condition|
out = `lighthouse #{target[:url]} --only-categories=performance --output json --quiet --chrome-flags="--headless" #{condition[:flags]}` # --output-path #{file_path}
response = JSON.parse(out) #File.open(file_path).read)
metric = "performance.lighthouse.#{condition[:name]}.#{target[:name]}"
value = (response['categories']['performance']['score']*100).to_i
p metric
p value
dog.emit_point(metric, value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment