riemann-tools 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +13 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.rubocop.yml +32 -0
- data/CHANGELOG.md +31 -2
- data/README.markdown +8 -24
- data/Rakefile +4 -2
- data/SECURITY.md +42 -0
- data/bin/riemann-apache-status +92 -78
- data/bin/riemann-bench +54 -49
- data/bin/riemann-cloudant +44 -40
- data/bin/riemann-consul +82 -76
- data/bin/riemann-dir-files-count +53 -47
- data/bin/riemann-dir-space +53 -47
- data/bin/riemann-diskstats +78 -75
- data/bin/riemann-fd +68 -48
- data/bin/riemann-freeswitch +108 -103
- data/bin/riemann-haproxy +46 -40
- data/bin/riemann-health +4 -343
- data/bin/riemann-kvminstance +18 -13
- data/bin/riemann-memcached +35 -29
- data/bin/riemann-net +4 -104
- data/bin/riemann-nginx-status +74 -67
- data/bin/riemann-ntp +4 -33
- data/bin/riemann-portcheck +40 -31
- data/bin/riemann-proc +96 -90
- data/bin/riemann-varnish +51 -45
- data/bin/riemann-zookeeper +38 -34
- data/lib/riemann/tools/health.rb +347 -0
- data/lib/riemann/tools/net.rb +104 -0
- data/lib/riemann/tools/ntp.rb +41 -0
- data/lib/riemann/tools/version.rb +1 -1
- data/lib/riemann/tools.rb +37 -40
- data/riemann-tools.gemspec +4 -1
- data/tools/riemann-aws/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-aws/bin/riemann-aws-billing +72 -66
- data/tools/riemann-aws/bin/riemann-aws-rds-status +55 -41
- data/tools/riemann-aws/bin/riemann-aws-sqs-status +37 -31
- data/tools/riemann-aws/bin/riemann-aws-status +63 -51
- data/tools/riemann-aws/bin/riemann-elb-metrics +149 -148
- data/tools/riemann-aws/bin/riemann-s3-list +70 -65
- data/tools/riemann-aws/bin/riemann-s3-status +85 -82
- data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-chronos/bin/riemann-chronos +136 -119
- data/tools/riemann-docker/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-docker/bin/riemann-docker +163 -174
- data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +155 -147
- data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-marathon/bin/riemann-marathon +138 -122
- data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-mesos/bin/riemann-mesos +125 -110
- data/tools/riemann-munin/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-munin/bin/riemann-munin +28 -22
- data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +226 -222
- data/tools/riemann-riak/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-riak/bin/riemann-riak +281 -289
- data/tools/riemann-riak/riak_status/riak_status.rb +39 -39
- metadata +65 -16
data/bin/riemann-diskstats
CHANGED
@@ -1,95 +1,98 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Process.setproctitle($PROGRAM_NAME)
|
4
5
|
require 'rubygems'
|
5
6
|
require 'riemann/tools'
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
module Riemann
|
9
|
+
module Tools
|
10
|
+
class Diskstats
|
11
|
+
include Riemann::Tools
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
opt :devices, 'Devices to monitor', type: :strings, default: nil
|
14
|
+
opt :ignore_devices, 'Devices to ignore', type: :strings, default: nil
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
def initialize
|
17
|
+
@old_state = nil
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
20
|
+
def state
|
21
|
+
f = File.read('/proc/diskstats')
|
22
|
+
state = f.split("\n").reject { |d| d =~ /(ram|loop)/ }.each_with_object({}) do |line, s|
|
23
|
+
next unless line =~ /^(?:\s+\d+){2}\s+([\w\d\-]+) (.*)$/
|
24
|
+
|
25
|
+
dev = Regexp.last_match(1)
|
26
|
+
|
27
|
+
['reads reqs',
|
28
|
+
'reads merged',
|
29
|
+
'reads sector',
|
30
|
+
'reads time',
|
31
|
+
'writes reqs',
|
32
|
+
'writes merged',
|
33
|
+
'writes sector',
|
34
|
+
'writes time',
|
35
|
+
'io reqs',
|
36
|
+
'io time',
|
37
|
+
'io weighted',].map do |service|
|
38
|
+
"#{dev} #{service}"
|
39
|
+
end.zip( # rubocop:disable Style/MultilineBlockChain
|
40
|
+
Regexp.last_match(2).split(/\s+/).map(&:to_i),
|
41
|
+
).each do |service, value|
|
42
|
+
s[service] = value
|
43
|
+
end
|
40
44
|
end
|
41
|
-
end
|
42
45
|
|
43
|
-
|
44
|
-
|
46
|
+
# Filter interfaces
|
47
|
+
if (is = opts[:devices])
|
48
|
+
state = state.select do |service, _value|
|
49
|
+
is.include? service.split(' ').first
|
50
|
+
end
|
51
|
+
end
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
53
|
+
if (ign = opts[:ignore_devices])
|
54
|
+
state = state.reject do |service, _value|
|
55
|
+
ign.include? service.split(' ').first
|
56
|
+
end
|
57
|
+
end
|
52
58
|
|
53
|
-
|
54
|
-
state = state.reject do |service, value|
|
55
|
-
ign.include? service.split(' ').first
|
59
|
+
state
|
56
60
|
end
|
57
|
-
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
62
|
+
def tick
|
63
|
+
state = self.state
|
64
|
+
|
65
|
+
if @old_state
|
66
|
+
state.each do |service, metric|
|
67
|
+
if service =~ /io reqs$/
|
68
|
+
report(
|
69
|
+
service: "diskstats #{service}",
|
70
|
+
metric: metric,
|
71
|
+
state: 'ok',
|
72
|
+
)
|
73
|
+
else
|
74
|
+
delta = metric - @old_state[service]
|
75
|
+
|
76
|
+
report(
|
77
|
+
service: "diskstats #{service}",
|
78
|
+
metric: (delta.to_f / opts[:interval]),
|
79
|
+
state: 'ok',
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
next unless service =~ /io time$/
|
84
|
+
|
85
|
+
report(
|
86
|
+
service: "diskstats #{service.gsub(/time/, 'util')}",
|
87
|
+
metric: (delta.to_f / (opts[:interval] * 1000)),
|
88
|
+
state: 'ok',
|
89
|
+
)
|
90
|
+
end
|
82
91
|
end
|
83
92
|
|
84
|
-
|
85
|
-
report(:service => "diskstats " + service.gsub(/time/, 'util'),
|
86
|
-
:metric => (delta.to_f / (opts[:interval]*1000)),
|
87
|
-
:state => "ok")
|
88
|
-
end
|
93
|
+
@old_state = state
|
89
94
|
end
|
90
95
|
end
|
91
|
-
|
92
|
-
@old_state = state
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
data/bin/riemann-fd
CHANGED
@@ -1,66 +1,86 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Process.setproctitle($PROGRAM_NAME)
|
3
5
|
|
4
6
|
# Reports current file descriptor use to riemann.
|
5
7
|
# By default reports the total system fd usage, can also report usage of individual processes
|
6
8
|
|
7
|
-
require File.expand_path('
|
9
|
+
require File.expand_path('../lib/riemann/tools', __dir__)
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
module Riemann
|
12
|
+
module Tools
|
13
|
+
class Health
|
14
|
+
include Riemann::Tools
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
opt :fd_sys_warning, 'open file descriptor threshold for system', default: 800
|
17
|
+
opt :fd_sys_critical, 'open file descriptor critical threshold for system', default: 900
|
18
|
+
opt :fd_proc_warning, 'open file descriptor threshold for process', default: 800
|
19
|
+
opt :fd_proc_critical, 'open file descriptor critical threshold for process', default: 900
|
20
|
+
opt :processes, 'list of processes to measure fd usage in addition to system total', type: :ints
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def initialize
|
23
|
+
@limits = {
|
24
|
+
fd: { critical: opts[:fd_sys_critical], warning: opts[:fd_sys_warning] },
|
25
|
+
process: { critical: opts[:fd_proc_critical], warning: opts[:fd_proc_warning] },
|
26
|
+
}
|
27
|
+
ostype = `uname -s`.chomp.downcase
|
28
|
+
case ostype
|
29
|
+
when 'freebsd'
|
30
|
+
@fd = method :freebsd_fd
|
31
|
+
else
|
32
|
+
puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == 'linux'
|
33
|
+
@fd = method :linux_fd
|
34
|
+
end
|
35
|
+
end
|
27
36
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
def alert(service, state, metric, description)
|
38
|
+
report(
|
39
|
+
service: service.to_s,
|
40
|
+
state: state.to_s,
|
41
|
+
metric: metric.to_f,
|
42
|
+
description: description,
|
43
|
+
)
|
44
|
+
end
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
def freebsd_fd
|
47
|
+
sys_used = Integer(`sysctl -n kern.openfiles`)
|
48
|
+
if sys_used > @limits[:fd][:critical]
|
49
|
+
alert 'fd sys', :critical, sys_used, "system is using #{sys_used} fds"
|
50
|
+
elsif sys_used > @limits[:fd][:warning]
|
51
|
+
alert 'fd sys', :warning, sys_used, "system is using #{sys_used} fds"
|
52
|
+
else
|
53
|
+
alert 'fd sys', :ok, sys_used, "system is using #{sys_used} fds"
|
54
|
+
end
|
55
|
+
end
|
46
56
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
alert
|
53
|
-
elsif used > @limits[:process][:warning]
|
54
|
-
alert "fd #{name} #{process}", :warning, used, "process #{name} #{process} is using #{used} fds"
|
57
|
+
def linux_fd
|
58
|
+
sys_used = Integer(`lsof | wc -l`)
|
59
|
+
if sys_used > @limits[:fd][:critical]
|
60
|
+
alert 'fd sys', :critical, sys_used, "system is using #{sys_used} fds"
|
61
|
+
elsif sys_used > @limits[:fd][:warning]
|
62
|
+
alert 'fd sys', :warning, sys_used, "system is using #{sys_used} fds"
|
55
63
|
else
|
56
|
-
alert
|
64
|
+
alert 'fd sys', :ok, sys_used, "system is using #{sys_used} fds"
|
65
|
+
end
|
66
|
+
|
67
|
+
opts[:processes]&.each do |process|
|
68
|
+
used = Integer(`lsof -p #{process} | wc -l`)
|
69
|
+
name, _pid = `ps axo comm,pid | grep -w #{process}`.split
|
70
|
+
if used > @limits[:process][:critical]
|
71
|
+
alert "fd #{name} #{process}", :critical, used, "process #{name} #{process} is using #{used} fds"
|
72
|
+
elsif used > @limits[:process][:warning]
|
73
|
+
alert "fd #{name} #{process}", :warning, used, "process #{name} #{process} is using #{used} fds"
|
74
|
+
else
|
75
|
+
alert "fd #{name} #{process}", :ok, used, "process #{name} #{process} is using #{used} fds"
|
76
|
+
end
|
57
77
|
end
|
58
78
|
end
|
59
|
-
end
|
60
|
-
end
|
61
79
|
|
62
|
-
|
63
|
-
|
80
|
+
def tick
|
81
|
+
@fd.call
|
82
|
+
end
|
83
|
+
end
|
64
84
|
end
|
65
85
|
end
|
66
86
|
|
data/bin/riemann-freeswitch
CHANGED
@@ -1,119 +1,124 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'English'
|
5
5
|
|
6
|
-
|
7
|
-
include Riemann::Tools
|
6
|
+
Process.setproctitle($PROGRAM_NAME)
|
8
7
|
|
9
|
-
|
10
|
-
opt :calls_critical, "Calls critical threshold", :default => 300
|
11
|
-
opt :pid_file, "FreeSWITCH daemon pidfile", :type => String, :default => "/var/run/freeswitch/freeswitch.pid"
|
8
|
+
require File.expand_path('../lib/riemann/tools', __dir__)
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
10
|
+
module Riemann
|
11
|
+
module Tools
|
12
|
+
class FreeSWITCH
|
13
|
+
include Riemann::Tools
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
false
|
23
|
-
rescue Errno::ESRCH
|
24
|
-
true
|
25
|
-
end
|
26
|
-
end
|
15
|
+
opt :calls_warning, 'Calls warning threshold', default: 100
|
16
|
+
opt :calls_critical, 'Calls critical threshold', default: 300
|
17
|
+
opt :pid_file, 'FreeSWITCH daemon pidfile', type: String, default: '/var/run/freeswitch/freeswitch.pid'
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:metric => metric.to_f,
|
33
|
-
:description => description
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
def exec_with_timeout(cmd, timeout)
|
38
|
-
pid = Process.spawn(cmd, {[:err,:out] => :close, :pgroup => true})
|
39
|
-
begin
|
40
|
-
Timeout.timeout(timeout) do
|
41
|
-
Process.waitpid(pid, 0)
|
42
|
-
$?.exitstatus == 0
|
19
|
+
def initialize
|
20
|
+
@limits = {
|
21
|
+
calls: { critical: opts[:calls_critical], warning: opts[:calls_warning] },
|
22
|
+
}
|
43
23
|
end
|
44
|
-
rescue Timeout::Error
|
45
|
-
Process.kill(15, -Process.getpgid(pid))
|
46
|
-
puts "Killed pid: #{pid}"
|
47
|
-
false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def tick
|
52
|
-
# Determine how many current calls I have according to FreeSWITCH
|
53
|
-
fs_calls = %x[fs_cli -x "show calls count"| grep -Po '^\\d+'].to_i
|
54
|
-
|
55
|
-
# Determine how many current channels I have according to FreeSWITCH
|
56
|
-
fs_channels = %x[fs_cli -x "show channels count"| grep -Po '^\\d+'].to_i
|
57
|
-
|
58
|
-
# Determine how many conferences I have according to FreeSWITCH
|
59
|
-
fs_conferences = %x[fs_cli -x "conference list"| grep -Pco '^Conference'].to_i
|
60
|
-
|
61
|
-
# Try to read pidfile. If it fails use Devil's dummy PID
|
62
|
-
begin
|
63
|
-
fs_pid = File.read(opts[:pid_file]).to_i
|
64
|
-
rescue
|
65
|
-
puts "Couldn't read pidfile: #{opts[:pid_file]}"
|
66
|
-
fs_pid = -666
|
67
|
-
end
|
68
|
-
|
69
|
-
fs_threads = fs_pid > 0 ? %x[ps huH p #{fs_pid} | wc -l].to_i : 0
|
70
24
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
alert "FreeSWITCH current calls", :ok, fs_calls, "Number of calls are #{fs_calls}"
|
78
|
-
end
|
79
|
-
|
80
|
-
# Submit channels to riemann
|
81
|
-
if fs_channels > @limits[:calls][:critical]
|
82
|
-
alert "FreeSWITCH current channels", :critical, fs_channels, "Number of channels are #{fs_channels}"
|
83
|
-
elsif fs_channels > @limits[:calls][:warning]
|
84
|
-
alert "FreeSWITCH current channels", :warning, fs_channels, "Number of channels are #{fs_channels}"
|
85
|
-
else
|
86
|
-
alert "FreeSWITCH current channels", :ok, fs_channels, "Number of channels are #{fs_channels}"
|
87
|
-
end
|
88
|
-
|
89
|
-
# Submit conferences to riemann
|
90
|
-
if fs_conferences > @limits[:calls][:critical]
|
91
|
-
alert "FreeSWITCH current conferences", :critical, fs_conferences, "Number of conferences are #{fs_conferences}"
|
92
|
-
elsif fs_conferences > @limits[:calls][:warning]
|
93
|
-
alert "FreeSWITCH current conferences", :warning, fs_conferences, "Number of conferences are #{fs_conferences}"
|
94
|
-
else
|
95
|
-
alert "FreeSWITCH current conferences", :ok, fs_conferences, "Number of conferences are #{fs_conferences}"
|
96
|
-
end
|
25
|
+
def dead_proc?(pid)
|
26
|
+
Process.getpgid(pid)
|
27
|
+
false
|
28
|
+
rescue Errno::ESRCH
|
29
|
+
true
|
30
|
+
end
|
97
31
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
32
|
+
def alert(service, state, metric, description)
|
33
|
+
report(
|
34
|
+
service: service.to_s,
|
35
|
+
state: state.to_s,
|
36
|
+
metric: metric.to_f,
|
37
|
+
description: description,
|
38
|
+
)
|
39
|
+
end
|
102
40
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
41
|
+
def exec_with_timeout(cmd, timeout)
|
42
|
+
pid = Process.spawn(cmd, { %i[err out] => :close, :pgroup => true })
|
43
|
+
begin
|
44
|
+
Timeout.timeout(timeout) do
|
45
|
+
Process.waitpid(pid, 0)
|
46
|
+
$CHILD_STATUS.exitstatus.zero?
|
47
|
+
end
|
48
|
+
rescue Timeout::Error
|
49
|
+
Process.kill(15, -Process.getpgid(pid))
|
50
|
+
puts "Killed pid: #{pid}"
|
51
|
+
false
|
52
|
+
end
|
53
|
+
end
|
109
54
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
55
|
+
def tick
|
56
|
+
# Determine how many current calls I have according to FreeSWITCH
|
57
|
+
fs_calls = `fs_cli -x "show calls count"| grep -Po '^\\d+'`.to_i
|
58
|
+
|
59
|
+
# Determine how many current channels I have according to FreeSWITCH
|
60
|
+
fs_channels = `fs_cli -x "show channels count"| grep -Po '^\\d+'`.to_i
|
61
|
+
|
62
|
+
# Determine how many conferences I have according to FreeSWITCH
|
63
|
+
fs_conferences = `fs_cli -x "conference list"| grep -Pco '^Conference'`.to_i
|
64
|
+
|
65
|
+
# Try to read pidfile. If it fails use Devil's dummy PID
|
66
|
+
begin
|
67
|
+
fs_pid = File.read(opts[:pid_file]).to_i
|
68
|
+
rescue StandardError
|
69
|
+
puts "Couldn't read pidfile: #{opts[:pid_file]}"
|
70
|
+
fs_pid = -666
|
71
|
+
end
|
72
|
+
|
73
|
+
fs_threads = fs_pid.positive? ? `ps huH p #{fs_pid} | wc -l`.to_i : 0
|
74
|
+
|
75
|
+
# Submit calls to riemann
|
76
|
+
if fs_calls > @limits[:calls][:critical]
|
77
|
+
alert 'FreeSWITCH current calls', :critical, fs_calls, "Number of calls are #{fs_calls}"
|
78
|
+
elsif fs_calls > @limits[:calls][:warning]
|
79
|
+
alert 'FreeSWITCH current calls', :warning, fs_calls, "Number of calls are #{fs_calls}"
|
80
|
+
else
|
81
|
+
alert 'FreeSWITCH current calls', :ok, fs_calls, "Number of calls are #{fs_calls}"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Submit channels to riemann
|
85
|
+
if fs_channels > @limits[:calls][:critical]
|
86
|
+
alert 'FreeSWITCH current channels', :critical, fs_channels, "Number of channels are #{fs_channels}"
|
87
|
+
elsif fs_channels > @limits[:calls][:warning]
|
88
|
+
alert 'FreeSWITCH current channels', :warning, fs_channels, "Number of channels are #{fs_channels}"
|
89
|
+
else
|
90
|
+
alert 'FreeSWITCH current channels', :ok, fs_channels, "Number of channels are #{fs_channels}"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Submit conferences to riemann
|
94
|
+
if fs_conferences > @limits[:calls][:critical]
|
95
|
+
alert 'FreeSWITCH current conferences', :critical, fs_conferences,
|
96
|
+
"Number of conferences are #{fs_conferences}"
|
97
|
+
elsif fs_conferences > @limits[:calls][:warning]
|
98
|
+
alert 'FreeSWITCH current conferences', :warning, fs_conferences,
|
99
|
+
"Number of conferences are #{fs_conferences}"
|
100
|
+
else
|
101
|
+
alert 'FreeSWITCH current conferences', :ok, fs_conferences, "Number of conferences are #{fs_conferences}"
|
102
|
+
end
|
103
|
+
|
104
|
+
# Submit threads to riemann
|
105
|
+
alert 'FreeSWITCH current threads', :ok, fs_threads, "Number of threads are #{fs_threads}" if fs_threads
|
106
|
+
|
107
|
+
# Submit status to riemann
|
108
|
+
if dead_proc?(fs_pid)
|
109
|
+
alert 'FreeSWITCH status', :critical, -1, 'FreeSWITCH service status: not running'
|
110
|
+
else
|
111
|
+
alert 'FreeSWITCH status', :ok, nil, 'FreeSWITCH service status: running'
|
112
|
+
end
|
113
|
+
|
114
|
+
# Submit CLI status to riemann using timeout in case it's unresponsive
|
115
|
+
if exec_with_timeout('fs_cli -x status', 2)
|
116
|
+
alert 'FreeSWITCH CLI status', :ok, nil, 'FreeSWITCH CLI status: responsive'
|
117
|
+
else
|
118
|
+
alert 'FreeSWITCH CLI status', :critical, -1, 'FreeSWITCH CLI status: not responding'
|
119
|
+
end
|
120
|
+
end
|
115
121
|
end
|
116
|
-
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
data/bin/riemann-haproxy
CHANGED
@@ -1,59 +1,65 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Process.setproctitle($PROGRAM_NAME)
|
3
5
|
|
4
6
|
# Gathers haproxy CSV statistics and submits them to Riemann.
|
5
7
|
|
6
|
-
require File.expand_path('
|
8
|
+
require File.expand_path('../lib/riemann/tools', __dir__)
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
module Riemann
|
11
|
+
module Tools
|
12
|
+
class Haproxy
|
13
|
+
include Riemann::Tools
|
14
|
+
require 'net/http'
|
15
|
+
require 'csv'
|
12
16
|
|
13
|
-
|
17
|
+
opt :stats_url, 'Full url to haproxy stats (eg: https://user:password@host.com:9999/stats)', required: true,
|
18
|
+
type: :string
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
def initialize
|
21
|
+
@uri = URI("#{opts[:stats_url]};csv")
|
22
|
+
end
|
23
|
+
|
24
|
+
def tick
|
25
|
+
csv.each do |row|
|
26
|
+
row = row.to_hash
|
27
|
+
ns = "haproxy #{row['pxname']} #{row['svname']}"
|
28
|
+
row.each do |property, metric|
|
29
|
+
next if property.nil? || property == 'pxname' || property == 'svname'
|
30
|
+
|
31
|
+
report(
|
32
|
+
host: @uri.host,
|
33
|
+
service: "#{ns} #{property}",
|
34
|
+
metric: metric.to_f,
|
35
|
+
tags: ['haproxy'],
|
36
|
+
)
|
37
|
+
end
|
18
38
|
|
19
|
-
def tick
|
20
|
-
csv = CSV.parse(get_csv.body.split("# ")[1], { :headers => true })
|
21
|
-
csv.each do |row|
|
22
|
-
row = row.to_hash
|
23
|
-
ns = "haproxy #{row['pxname']} #{row['svname']}"
|
24
|
-
row.each do |property, metric|
|
25
|
-
unless (property.nil? || property == 'pxname' || property == 'svname')
|
26
39
|
report(
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
40
|
+
host: @uri.host,
|
41
|
+
service: "#{ns} state",
|
42
|
+
state: (%w[UP OPEN].include?(row['status']) ? 'ok' : 'critical'),
|
43
|
+
tags: ['haproxy'],
|
31
44
|
)
|
32
45
|
end
|
33
46
|
end
|
34
47
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
http.start do |h|
|
48
|
-
get = Net::HTTP::Get.new(@uri.request_uri)
|
49
|
-
unless @uri.userinfo.nil?
|
50
|
-
userinfo = @uri.userinfo.split(":")
|
51
|
-
get.basic_auth userinfo[0], userinfo[1]
|
48
|
+
def csv
|
49
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
50
|
+
http.use_ssl = true if @uri.scheme == 'https'
|
51
|
+
http.start do |h|
|
52
|
+
get = Net::HTTP::Get.new(@uri.request_uri)
|
53
|
+
unless @uri.userinfo.nil?
|
54
|
+
userinfo = @uri.userinfo.split(':')
|
55
|
+
get.basic_auth userinfo[0], userinfo[1]
|
56
|
+
end
|
57
|
+
h.request get
|
58
|
+
end
|
59
|
+
CSV.parse(http.body.split('# ')[1], { headers: true })
|
52
60
|
end
|
53
|
-
h.request get
|
54
61
|
end
|
55
62
|
end
|
56
|
-
|
57
63
|
end
|
58
64
|
|
59
65
|
Riemann::Tools::Haproxy.run
|