Created
July 8, 2015 06:26
-
-
Save FredrikL/a0f149414411c1874a53 to your computer and use it in GitHub Desktop.
ping stats to influxdb
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
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