forked from rashidkpc/graphital
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphital.rb
executable file
·42 lines (38 loc) · 878 Bytes
/
graphital.rb
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
load '/opt/graphital/graphital.conf'
require 'socket'
require 'timeout'
def vitals
vitals = Array.new
Dir.foreach("#{$PATH}") do |item|
next if item == '.' or item == '..'
vitals << Thread.new{ Thread.current[:output] = run_vital(item) }
end
vitals
end
def run_vital(item)
vital = nil
name = item.split('.').first
status = Timeout::timeout($INTERVAL) {
vital = `#{$PATH}/#{item}`.split("\n")
vital = name + "." + vital.join("\n#{name}.")
}
vital
end
def vital_output(host,port)
socket = TCPSocket.open(host,port)
time = Time.now.to_i.to_s
output = ''
vitals.each do |vital|
vital.join
vital[:output].split("\n").each do |vital|
output += "#{$PREFIX}.#{vital} #{time}\n"
end
end
puts output
socket.print(output)
socket.close
end
loop {
output = Thread.new{vital_output($HOST,$PORT)}
sleep $INTERVAL;
}