blob: 8549886ae1c78305d9234f296608a6198fb030a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
require 'rubygems'
require 'mongo'
require './settings.rb'
include Mongo
settings = nil
slock = false
threads = {}
client = MongoClient.new(HOME, 27017)
cdb = client['configs']
rdb = client['results']
ccoll = cdb[THIS]
rcoll = rdb[THIS]
ccoll.find.each do |doc|
settings = doc
end
threads["pingthread"] = Thread.new do loop do
unless slock
slock = true
results = {"timestamp" => Time.now.to_i}
settings["neighbours"].each do |neighbour|
pingtime = %x[ping -c1 #{neighbour}][/time=(.*?) ms/, 1].to_f
results.merge!({neighbour => pingtime})
end
rcoll.insert(results)
slock = false
sleep(settings["pinginterval"])
end
end end
threads["threadupdater"] = Thread.new do loop do
unless slock
slock = true
ccoll.find.each do |doc|
settings = doc
end
slock = false
sleep(settings["configttl"])
end
end end
threads.each do |name, thr|
thr.join
end
|