Skip to content

Instantly share code, notes, and snippets.

@FredrikL
Created July 8, 2015 06:26
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 FredrikL/a0f149414411c1874a53 to your computer and use it in GitHub Desktop.
Save FredrikL/a0f149414411c1874a53 to your computer and use it in GitHub Desktop.
ping stats to influxdb
require 'net/ping'
require 'influxdb'
@icmp = Net::Ping::External.new('8.8.8.8')
rtary = []
pingfails = 0
repeat = 5
(1..repeat).each do
if @icmp.ping
rtary << @icmp.duration
else
pingfails += 1
end
end
avg = rtary.inject(0) {|sum, i| sum + i}/(repeat - pingfails)
@influxdb = InfluxDB::Client.new "internet_status", :username => "root", :password => "root"
data = {
:avg => avg,
:loss => pingfails
}
@influxdb.write_point("ping", data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment