Skip to content

Instantly share code, notes, and snippets.

@apeckham
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeckham/60a2c8e648d89a44c7af to your computer and use it in GitHub Desktop.
Save apeckham/60a2c8e648d89a44c7af to your computer and use it in GitHub Desktop.
speedtest-cli to librato
results = %x'speedtest-cli --server 5026'
p results
source = results[/Testing from ([^\(]+) /, 1].gsub(/[^\w]+/, '')
ping, download, upload = results.scan(/\d+\.\d+(?= Mbits| ms)/)
data = {
'gauges[0][name]' => 'speedtest.ping',
'gauges[0][value]' => ping,
'gauges[0][source]' => source,
'gauges[1][name]' => 'speedtest.download',
'gauges[1][value]' => download,
'gauges[1][source]' => source,
'gauges[2][name]' => 'speedtest.upload',
'gauges[2][value]' => upload,
'gauges[2][source]' => source
}
p data
post = data.map { |k,v| "#{k}=#{v}" }.join('&')
system "curl -v -u #{ENV['LIBRATO_USERNAME']}:#{ENV['LIBRATO_PASSWORD']} -d '#{post}' -X POST https://metrics-api.librato.com/v1/metrics"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment