Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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