Last active
August 29, 2015 14:05
-
-
Save apeckham/60a2c8e648d89a44c7af to your computer and use it in GitHub Desktop.
speedtest-cli to librato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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