Created
August 23, 2015 19:05
-
-
Save ross-nordstrom/558ebdff2e199e40bb81 to your computer and use it in GitHub Desktop.
Speedtest.net Ping/Download/Upload breakdown
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
#!/usr/bin/env ruby | |
require 'json' | |
# | |
# Output with --simple looks like: | |
# Ping: 31.823 ms | |
# Download: 80.53 Mbit/s | |
# Upload: 11.25 Mbit/s | |
# | |
speed = `speedtest --simple` | |
data = speed.split("\n").reduce({}) do |acc, s| | |
parts = s.split(' ') | |
key = parts[0].split(':')[0] | |
val = parts[1].to_f | |
acc[key] = val | |
acc | |
end | |
if data.empty? | |
puts "No speedtest data found. Did you install the speedtest cli? (https://github.com/sivel/speedtest-cli#installation)" | |
exit 1 | |
end | |
# Calculate states | |
data[:ping_state] = data['Ping'] > 200 ? 3 : (data['Ping'] > 75 ? 2 : 1) | |
data[:download_state] = data['Download'] < 3 ? 3 : (data['Download'] < 10 ? 2 : 1) | |
data[:upload_state] = data['Upload'] < 1 ? 3 : (data['Upload'] < 5 ? 2 : 1) | |
puts data.to_json.gsub(/"/, "'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment