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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +13 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.rubocop.yml +32 -0
  6. data/CHANGELOG.md +31 -2
  7. data/README.markdown +8 -24
  8. data/Rakefile +4 -2
  9. data/SECURITY.md +42 -0
  10. data/bin/riemann-apache-status +92 -78
  11. data/bin/riemann-bench +54 -49
  12. data/bin/riemann-cloudant +44 -40
  13. data/bin/riemann-consul +82 -76
  14. data/bin/riemann-dir-files-count +53 -47
  15. data/bin/riemann-dir-space +53 -47
  16. data/bin/riemann-diskstats +78 -75
  17. data/bin/riemann-fd +68 -48
  18. data/bin/riemann-freeswitch +108 -103
  19. data/bin/riemann-haproxy +46 -40
  20. data/bin/riemann-health +4 -343
  21. data/bin/riemann-kvminstance +18 -13
  22. data/bin/riemann-memcached +35 -29
  23. data/bin/riemann-net +4 -104
  24. data/bin/riemann-nginx-status +74 -67
  25. data/bin/riemann-ntp +4 -33
  26. data/bin/riemann-portcheck +40 -31
  27. data/bin/riemann-proc +96 -90
  28. data/bin/riemann-varnish +51 -45
  29. data/bin/riemann-zookeeper +38 -34
  30. data/lib/riemann/tools/health.rb +347 -0
  31. data/lib/riemann/tools/net.rb +104 -0
  32. data/lib/riemann/tools/ntp.rb +41 -0
  33. data/lib/riemann/tools/version.rb +1 -1
  34. data/lib/riemann/tools.rb +37 -40
  35. data/riemann-tools.gemspec +4 -1
  36. data/tools/riemann-aws/{Rakefile.rb → Rakefile} +2 -0
  37. data/tools/riemann-aws/bin/riemann-aws-billing +72 -66
  38. data/tools/riemann-aws/bin/riemann-aws-rds-status +55 -41
  39. data/tools/riemann-aws/bin/riemann-aws-sqs-status +37 -31
  40. data/tools/riemann-aws/bin/riemann-aws-status +63 -51
  41. data/tools/riemann-aws/bin/riemann-elb-metrics +149 -148
  42. data/tools/riemann-aws/bin/riemann-s3-list +70 -65
  43. data/tools/riemann-aws/bin/riemann-s3-status +85 -82
  44. data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +2 -0
  45. data/tools/riemann-chronos/bin/riemann-chronos +136 -119
  46. data/tools/riemann-docker/{Rakefile.rb → Rakefile} +2 -0
  47. data/tools/riemann-docker/bin/riemann-docker +163 -174
  48. data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +2 -0
  49. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +155 -147
  50. data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +2 -0
  51. data/tools/riemann-marathon/bin/riemann-marathon +138 -122
  52. data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +2 -0
  53. data/tools/riemann-mesos/bin/riemann-mesos +125 -110
  54. data/tools/riemann-munin/{Rakefile.rb → Rakefile} +2 -0
  55. data/tools/riemann-munin/bin/riemann-munin +28 -22
  56. data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +2 -0
  57. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +226 -222
  58. data/tools/riemann-riak/{Rakefile.rb → Rakefile} +2 -0
  59. data/tools/riemann-riak/bin/riemann-riak +281 -289
  60. data/tools/riemann-riak/riak_status/riak_status.rb +39 -39
  61. metadata +65 -16
@@ -1,95 +1,98 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
3
- #
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
4
5
  require 'rubygems'
5
6
  require 'riemann/tools'
6
7
 
7
- class Riemann::Tools::Diskstats
8
- include Riemann::Tools
8
+ module Riemann
9
+ module Tools
10
+ class Diskstats
11
+ include Riemann::Tools
9
12
 
10
- opt :devices, "Devices to monitor", :type => :strings, :default => nil
11
- opt :ignore_devices, "Devices to ignore", :type => :strings, :default =>nil
13
+ opt :devices, 'Devices to monitor', type: :strings, default: nil
14
+ opt :ignore_devices, 'Devices to ignore', type: :strings, default: nil
12
15
 
13
- def initialize
14
- @old_state = nil
15
- end
16
+ def initialize
17
+ @old_state = nil
18
+ end
16
19
 
17
- def state
18
- f = File.read('/proc/diskstats')
19
- state = f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |s, line|
20
- if line =~ /^(?:\s+\d+){2}\s+([\w\d\-]+) (.*)$/
21
- dev = $1
22
-
23
- ['reads reqs',
24
- 'reads merged',
25
- 'reads sector',
26
- 'reads time',
27
- 'writes reqs',
28
- 'writes merged',
29
- 'writes sector',
30
- 'writes time',
31
- 'io reqs',
32
- 'io time',
33
- 'io weighted'
34
- ].map do |service|
35
- "#{dev} #{service}"
36
- end.zip(
37
- $2.split(/\s+/).map { |str| str.to_i }
38
- ).each do |service, value|
39
- s[service] = value
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
- s
44
- end
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
- # Filter interfaces
47
- if is = opts[:devices]
48
- state = state.select do |service, value|
49
- is.include? service.split(' ').first
50
- end
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
- if ign = opts[:ignore_devices]
54
- state = state.reject do |service, value|
55
- ign.include? service.split(' ').first
59
+ state
56
60
  end
57
- end
58
61
 
59
- state
60
- end
61
-
62
- def tick
63
- state = self.state
64
-
65
- if @old_state
66
- state.each do |service, metric|
67
-
68
- if service =~ /io reqs$/
69
- report(
70
- :service => "diskstats " + service,
71
- :metric => metric,
72
- :state => "ok"
73
- )
74
- else
75
- delta = metric - @old_state[service]
76
-
77
- report(
78
- :service => "diskstats " + service,
79
- :metric => (delta.to_f / opts[:interval]),
80
- :state => "ok"
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
- if service =~ /io time$/
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
- Process.setproctitle($0)
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('../../lib/riemann/tools', __FILE__)
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
8
10
 
9
- class Riemann::Tools::Health
10
- include Riemann::Tools
11
+ module Riemann
12
+ module Tools
13
+ class Health
14
+ include Riemann::Tools
11
15
 
12
- opt :fd_sys_warning, "open file descriptor threshold for system", :default => 800
13
- opt :fd_sys_critical, "open file descriptor critical threshold for system", :default => 900
14
- opt :fd_proc_warning, "open file descriptor threshold for process", :default => 800
15
- opt :fd_proc_critical, "open file descriptor critical threshold for process", :default => 900
16
- opt :processes, "list of processes to measure fd usage in addition to system total", :type => :ints
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
- def initialize
19
- @limits = {
20
- :fd => {:critical => opts[:fd_sys_critical], :warning => opts[:fd_sys_warning]},
21
- :process => {:critical => opts[:fd_proc_critical], :warning => opts[:fd_proc_warning]},
22
- }
23
- ostype = `uname -s`.chomp.downcase
24
- puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == "linux"
25
- @fd = method :linux_fd
26
- end
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
- def alert(service, state, metric, description)
29
- report(
30
- :service => service.to_s,
31
- :state => state.to_s,
32
- :metric => metric.to_f,
33
- :description => description
34
- )
35
- end
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
- def linux_fd
38
- sys_used = Integer(`lsof | wc -l`)
39
- if sys_used > @limits[:fd][:critical]
40
- alert "fd sys", :critical, sys_used, "system is using #{sys_used} fds"
41
- elsif sys_used > @limits[:fd][:warning]
42
- alert "fd sys", :warning, sys_used, "system is using #{sys_used} fds"
43
- else
44
- alert "fd sys", :ok, sys_used, "system is using #{sys_used} fds"
45
- end
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
- unless opts[:processes].nil?
48
- opts[:processes].each do |process|
49
- used = Integer(`lsof -p #{process} | wc -l`)
50
- name, pid = `ps axo comm,pid | grep -w #{process}`.split
51
- if used > @limits[:process][:critical]
52
- alert "fd #{name} #{process}", :critical, used, "process #{name} #{process} is using #{used} fds"
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 "fd #{name} #{process}", :ok, used, "process #{name} #{process} is using #{used} fds"
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
- def tick
63
- @fd.call
80
+ def tick
81
+ @fd.call
82
+ end
83
+ end
64
84
  end
65
85
  end
66
86
 
@@ -1,119 +1,124 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
3
 
4
- require File.expand_path('../../lib/riemann/tools', __FILE__)
4
+ require 'English'
5
5
 
6
- class Riemann::Tools::FreeSWITCH
7
- include Riemann::Tools
6
+ Process.setproctitle($PROGRAM_NAME)
8
7
 
9
- opt :calls_warning, "Calls warning threshold", :default => 100
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
- def initialize
14
- @limits = {
15
- :calls => {:critical => opts[:calls_critical], :warning => opts[:calls_warning]}
16
- }
17
- end
10
+ module Riemann
11
+ module Tools
12
+ class FreeSWITCH
13
+ include Riemann::Tools
18
14
 
19
- def dead_proc?(pid)
20
- begin
21
- Process.getpgid(pid)
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
- def alert(service, state, metric, description)
29
- report(
30
- :service => service.to_s,
31
- :state => state.to_s,
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
- # Submit calls to riemann
72
- if fs_calls > @limits[:calls][:critical]
73
- alert "FreeSWITCH current calls", :critical, fs_calls, "Number of calls are #{fs_calls}"
74
- elsif fs_calls > @limits[:calls][:warning]
75
- alert "FreeSWITCH current calls", :warning, fs_calls, "Number of calls are #{fs_calls}"
76
- else
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
- # Submit threads to riemann
99
- if fs_threads
100
- alert "FreeSWITCH current threads", :ok, fs_threads, "Number of threads are #{fs_threads}"
101
- end
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
- # Submit status to riemann
104
- if dead_proc?(fs_pid)
105
- alert "FreeSWITCH status", :critical, -1, "FreeSWITCH service status: not running"
106
- else
107
- alert "FreeSWITCH status", :ok, nil, "FreeSWITCH service status: running"
108
- end
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
- # Submit CLI status to riemann using timeout in case it's unresponsive
111
- if exec_with_timeout("fs_cli -x status", 2)
112
- alert "FreeSWITCH CLI status", :ok, nil, "FreeSWITCH CLI status: responsive"
113
- else
114
- alert "FreeSWITCH CLI status", :critical, -1, "FreeSWITCH CLI status: not responding"
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
- Process.setproctitle($0)
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('../../lib/riemann/tools', __FILE__)
8
+ require File.expand_path('../lib/riemann/tools', __dir__)
7
9
 
8
- class Riemann::Tools::Haproxy
9
- include Riemann::Tools
10
- require 'net/http'
11
- require 'csv'
10
+ module Riemann
11
+ module Tools
12
+ class Haproxy
13
+ include Riemann::Tools
14
+ require 'net/http'
15
+ require 'csv'
12
16
 
13
- opt :stats_url, "Full url to haproxy stats (eg: https://user:password@host.com:9999/stats)", :required => true, :type => :string
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
- def initialize
16
- @uri = URI(opts[:stats_url]+';csv')
17
- end
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
- :host => @uri.host,
28
- :service => "#{ns} #{property}",
29
- :metric => metric.to_f,
30
- :tags => ['haproxy']
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
- report(
36
- :host => @uri.host,
37
- :service => "#{ns} state",
38
- :state => (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical'),
39
- :tags => ['haproxy']
40
- )
41
- end
42
- end
43
-
44
- def get_csv
45
- http = Net::HTTP.new(@uri.host, @uri.port)
46
- http.use_ssl = true if @uri.scheme == 'https'
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