-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtpcheck.rb
74 lines (61 loc) · 1.81 KB
/
rtpcheck.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env ruby
require 'net/http'
require 'getoptlong'
require 'socket'
###################################################################################################
# Small demo ruby script for checking some local http stats and sending to graphite using sockets #
###################################################################################################
# Declaring options, variables and usage
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--server', '-s', GetoptLong::REQUIRED_ARGUMENT ],
[ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--sampling-interval', '-i', GetoptLong::OPTIONAL_ARGUMENT ]
)
server = nil
port = nil
sampling_interval = 30 #Default value
if ARGV[0] == nil
puts "usage: rtpengine.rb -s server -p port [-i <sampling_interval>] or -h/--help"
exit
end
# Parsing command line options
opts.each do |opt, arg|
case opt
when '--help'
puts <<-EOF
rtpengine.rb -s hostname -p port [-i <sampling_interval>]
-h, --help:
show help
-s, --server
server IP address, hostname
-p, --port
server port
-i, --sampling-interval
desired check interval
EOF
exit
when '--server'
server = arg
when '--port'
port = arg.to_i
when '--sampling-interval'
sampling_interval = arg
end
end
s = TCPSocket.open('127.0.0.1', 2003)
# Collection loop
while true do
start_run = Time.now.to_i
next_run = start_run + sampling_interval
# collect data and write values to a socket
data = Net::HTTP.get_response(server,'/metrics', port)
tmp = data.body
temp = tmp.split(':')[10]
sessions = temp.split('}')[0]
s.puts("jinglertp_EU.sessions #{sessions} #{Time.now.to_i}")
# sleep to make the interval
while((time_left = (next_run - Time.now.to_i)) > 0) do
sleep(time_left)
end
end