riemann-tools 0.2.14 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.docker/Dockerfile +7 -0
  3. data/.docker/publish.sh +35 -0
  4. data/.github/dependabot.yml +11 -0
  5. data/.github/workflows/ci.yml +42 -0
  6. data/.github/workflows/codeql-analysis.yml +72 -0
  7. data/.gitignore +6 -0
  8. data/.rspec +2 -0
  9. data/.rubocop.yml +32 -0
  10. data/.travis.yml +31 -0
  11. data/CHANGELOG.md +430 -0
  12. data/Gemfile +6 -0
  13. data/ISSUE_TEMPLATE.md +15 -0
  14. data/README.markdown +13 -16
  15. data/Rakefile +23 -0
  16. data/SECURITY.md +42 -0
  17. data/bin/riemann-apache-status +92 -77
  18. data/bin/riemann-bench +54 -48
  19. data/bin/riemann-cloudant +44 -39
  20. data/bin/riemann-consul +82 -75
  21. data/bin/riemann-dir-files-count +53 -46
  22. data/bin/riemann-dir-space +53 -46
  23. data/bin/riemann-diskstats +78 -74
  24. data/bin/riemann-fd +68 -47
  25. data/bin/riemann-freeswitch +108 -102
  26. data/bin/riemann-haproxy +46 -39
  27. data/bin/riemann-health +4 -335
  28. data/bin/riemann-kvminstance +18 -12
  29. data/bin/riemann-memcached +35 -28
  30. data/bin/riemann-net +4 -103
  31. data/bin/riemann-nginx-status +74 -66
  32. data/bin/riemann-ntp +4 -32
  33. data/bin/riemann-portcheck +40 -30
  34. data/bin/riemann-proc +96 -89
  35. data/bin/riemann-varnish +51 -44
  36. data/bin/riemann-zookeeper +38 -33
  37. data/lib/riemann/tools/health.rb +347 -0
  38. data/lib/riemann/tools/net.rb +104 -0
  39. data/lib/riemann/tools/ntp.rb +41 -0
  40. data/lib/riemann/tools/utils.rb +17 -0
  41. data/lib/riemann/tools/version.rb +7 -0
  42. data/lib/riemann/tools.rb +38 -31
  43. data/riemann-tools.gemspec +42 -0
  44. data/tools/riemann-aws/LICENSE +21 -0
  45. data/tools/riemann-aws/README.md +54 -0
  46. data/tools/riemann-aws/Rakefile +37 -0
  47. data/tools/riemann-aws/bin/riemann-aws-billing +93 -0
  48. data/tools/riemann-aws/bin/riemann-aws-rds-status +68 -0
  49. data/tools/riemann-aws/bin/riemann-aws-sqs-status +50 -0
  50. data/tools/riemann-aws/bin/riemann-aws-status +83 -0
  51. data/tools/riemann-aws/bin/riemann-elb-metrics +168 -0
  52. data/tools/riemann-aws/bin/riemann-s3-list +87 -0
  53. data/tools/riemann-aws/bin/riemann-s3-status +102 -0
  54. data/tools/riemann-chronos/LICENSE +21 -0
  55. data/tools/riemann-chronos/README.md +10 -0
  56. data/tools/riemann-chronos/Rakefile +37 -0
  57. data/tools/riemann-chronos/bin/riemann-chronos +161 -0
  58. data/tools/riemann-docker/LICENSE +21 -0
  59. data/tools/riemann-docker/README.md +10 -0
  60. data/tools/riemann-docker/Rakefile +36 -0
  61. data/tools/riemann-docker/bin/riemann-docker +206 -0
  62. data/tools/riemann-elasticsearch/LICENSE +21 -0
  63. data/tools/riemann-elasticsearch/README.md +10 -0
  64. data/tools/riemann-elasticsearch/Rakefile +37 -0
  65. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +174 -0
  66. data/tools/riemann-marathon/LICENSE +21 -0
  67. data/tools/riemann-marathon/README.md +10 -0
  68. data/tools/riemann-marathon/Rakefile +37 -0
  69. data/tools/riemann-marathon/bin/riemann-marathon +163 -0
  70. data/tools/riemann-mesos/LICENSE +21 -0
  71. data/tools/riemann-mesos/README.md +10 -0
  72. data/tools/riemann-mesos/Rakefile +37 -0
  73. data/tools/riemann-mesos/bin/riemann-mesos +146 -0
  74. data/tools/riemann-munin/LICENSE +21 -0
  75. data/tools/riemann-munin/README.md +10 -0
  76. data/tools/riemann-munin/Rakefile +36 -0
  77. data/tools/riemann-munin/bin/riemann-munin +43 -0
  78. data/tools/riemann-rabbitmq/LICENSE +21 -0
  79. data/tools/riemann-rabbitmq/README.md +10 -0
  80. data/tools/riemann-rabbitmq/Rakefile +37 -0
  81. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +273 -0
  82. data/tools/riemann-riak/LICENSE +21 -0
  83. data/tools/riemann-riak/README.md +10 -0
  84. data/tools/riemann-riak/Rakefile +36 -0
  85. data/tools/riemann-riak/bin/riemann-riak +323 -0
  86. data/tools/riemann-riak/bin/riemann-riak-keys +13 -0
  87. data/tools/riemann-riak/bin/riemann-riak-ring +9 -0
  88. data/tools/riemann-riak/riak_status/key_count.erl +13 -0
  89. data/tools/riemann-riak/riak_status/riak_status.rb +152 -0
  90. data/tools/riemann-riak/riak_status/ringready.erl +9 -0
  91. metadata +186 -37
@@ -1,21 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require File.expand_path('../../lib/riemann/tools', __FILE__)
4
+ Process.setproctitle($PROGRAM_NAME)
4
5
 
5
- class Riemann::Tools::KVM
6
- include Riemann::Tools
6
+ require File.expand_path('../lib/riemann/tools', __dir__)
7
7
 
8
- def tick
8
+ module Riemann
9
+ module Tools
10
+ class KVM
11
+ include Riemann::Tools
9
12
 
10
- #determine how many instances I have according to libvirt
11
- kvm_instances = %x[LANG=C virsh list | grep -c running]
13
+ def tick
14
+ # determine how many instances I have according to libvirt
15
+ kvm_instances = `LANG=C virsh list | grep -c running`
12
16
 
13
- #submit them to riemann
14
- report(
15
- :service => "KVM Running VMs",
16
- :metric => kvm_instances.to_i,
17
- :state => "info"
18
- )
17
+ # submit them to riemann
18
+ report(
19
+ service: 'KVM Running VMs',
20
+ metric: kvm_instances.to_i,
21
+ state: 'info',
22
+ )
23
+ end
24
+ end
19
25
  end
20
26
  end
21
27
 
@@ -1,36 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
2
5
 
3
6
  # Gathers memcached STATS and submits them to Riemann.
4
7
 
5
- require File.expand_path('../../lib/riemann/tools', __FILE__)
6
-
7
- class Riemann::Tools::Memcached
8
- include Riemann::Tools
9
- require 'socket'
10
-
11
- opt :memcached_host, "Memcached hostname", :default => 'localhost'
12
- opt :memcached_port, "Memcached port", :default => 11211
13
-
14
- def tick
15
- sock = TCPSocket.new(opts[:memcached_host], opts[:memcached_port])
16
- sock.print("stats\r\n")
17
- sock.flush
18
- stats = sock.gets
19
-
20
- data = {}
21
- while true
22
- stats = sock.gets
23
- break if stats.strip == 'END'
24
- m = stats.match /STAT (\w+) (\S+)/
25
- report(
26
- :host => opts[:memcached_host].dup,
27
- :service => "memcached #{m[1]}",
28
- :metric => m[2].to_f,
29
- :state => 'ok',
30
- :tags => ['memcached']
31
- )
8
+ require File.expand_path('../lib/riemann/tools', __dir__)
9
+
10
+ module Riemann
11
+ module Tools
12
+ class Memcached
13
+ include Riemann::Tools
14
+ require 'socket'
15
+
16
+ opt :memcached_host, 'Memcached hostname', default: 'localhost'
17
+ opt :memcached_port, 'Memcached port', default: 11_211
18
+
19
+ def tick
20
+ sock = TCPSocket.new(opts[:memcached_host], opts[:memcached_port])
21
+ sock.print("stats\r\n")
22
+ sock.flush
23
+ stats = sock.gets
24
+
25
+ loop do
26
+ stats = sock.gets
27
+ break if stats.strip == 'END'
28
+
29
+ m = stats.match(/STAT (\w+) (\S+)/)
30
+ report(
31
+ host: opts[:memcached_host].dup,
32
+ service: "memcached #{m[1]}",
33
+ metric: m[2].to_f,
34
+ state: 'ok',
35
+ tags: ['memcached'],
36
+ )
37
+ end
38
+ sock.close
39
+ end
32
40
  end
33
- sock.close
34
41
  end
35
42
  end
36
43
 
data/bin/riemann-net CHANGED
@@ -1,109 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- # Gathers network interface statistics and submits them to Riemann.
4
-
5
- require File.expand_path('../../lib/riemann/tools', __FILE__)
6
-
7
- class Riemann::Tools::Net
8
- include Riemann::Tools
9
-
10
- opt :interfaces, "Interfaces to monitor", :type => :strings, :default => nil
11
- opt :ignore_interfaces, "Interfaces to ignore", :type => :strings, :default =>['lo']
12
-
13
- def initialize
14
- @old_state = nil
15
- @interfaces = opts[:interfaces].map(&:dup) if opts[:interfaces]
16
- @ignore_interfaces = opts[:ignore_interfaces].map(&:dup)
17
- end
18
-
19
- def state
20
- f = File.read('/proc/net/dev')
21
- state = f.split("\n").inject({}) do |s, line|
22
- if line =~ /\s*(\w+?):\s*([\s\d]+)\s*/
23
- iface = $1
24
-
25
- ['rx bytes',
26
- 'rx packets',
27
- 'rx errs',
28
- 'rx drop',
29
- 'rx fifo',
30
- 'rx frame',
31
- 'rx compressed',
32
- 'rx multicast',
33
- 'tx bytes',
34
- 'tx packets',
35
- 'tx errs',
36
- 'tx drops',
37
- 'tx fifo',
38
- 'tx colls',
39
- 'tx carrier',
40
- 'tx compressed'].map do |service|
41
- "#{iface} #{service}"
42
- end.zip(
43
- $2.split(/\s+/).map { |str| str.to_i }
44
- ).each do |service, value|
45
- s[service] = value
46
- end
47
- end
48
-
49
- s
50
- end
4
+ Process.setproctitle($PROGRAM_NAME)
51
5
 
52
- # Filter interfaces
53
- if is = @interfaces
54
- state = state.select do |service, value|
55
- is.include? service.split(' ').first
56
- end
57
- end
58
-
59
- state = state.reject do |service, value|
60
- @ignore_interfaces.include? service.split(' ').first
61
- end
62
-
63
- state
64
- end
65
-
66
- def tick
67
- state = self.state
68
-
69
- if @old_state
70
- # Report services from `@old_state` that don't exist in `state` as expired
71
- @old_state.reject { |k| state.has_key?(k) }.each do |service, metric|
72
- report(:service => service.dup, :state => 'expired')
73
- end
74
-
75
- # Report delta for services that have values in both `@old_state` and `state`
76
- state.each do |service, metric|
77
- next unless @old_state.has_key?(service)
78
-
79
- delta = metric - @old_state[service]
80
- svc_state = case service
81
- when /drop$/
82
- if delta > 0
83
- 'warning'
84
- else
85
- 'ok'
86
- end
87
- when /errs$/
88
- if delta > 0
89
- 'warning'
90
- else
91
- 'ok'
92
- end
93
- else
94
- 'ok'
95
- end
6
+ # Gathers network interface statistics and submits them to Riemann.
96
7
 
97
- report(
98
- :service => service.dup,
99
- :metric => (delta.to_f / opts[:interval]),
100
- :state => svc_state
101
- )
102
- end
103
- end
8
+ require 'riemann/tools/net'
104
9
 
105
- @old_state = state
106
- end
107
- end
108
-
109
10
  Riemann::Tools::Net.run
@@ -1,82 +1,90 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
2
5
 
3
6
  # Gathers nginx status stub statistics and submits them to Riemann.
4
7
  # See http://wiki.nginx.org/HttpStubStatusModule for configuring Nginx appropriately
5
8
 
6
- require File.expand_path('../../lib/riemann/tools', __FILE__)
7
-
8
- class Riemann::Tools::NginxStatus
9
- include Riemann::Tools
10
- require 'net/http'
11
- require 'uri'
12
-
13
- opt :uri, "Nginx Stub Status URI", :default => 'http://localhost:8080/nginx_status'
14
- opt :checks, "Which metrics to report.", :type => :strings, :default => %w{active accepted handled requests reading writing waiting}
15
- opt :active_warning, "Active connections warning threshold", :default => 0
16
- opt :active_critical, "Active connections critical threshold", :default => 0
17
- opt :reading_warning, "Reading connections warning threshold", :default => 0
18
- opt :reading_critical, "Reading connections critical threshold", :default => 0
19
- opt :writing_warning, "Writing connections warning threshold", :default => 0
20
- opt :writing_critical, "Writing connections critical threshold", :default => 0
21
- opt :waiting_warning, "Waiting connections warning threshold", :default => 0
22
- opt :waiting_critical, "Waiting connections critical threshold", :default => 0
23
-
24
- def initialize
25
- @uri = URI.parse(opts[:uri])
26
-
27
- # sample response:
28
- #
29
- # Active connections: 1
30
- # server accepts handled requests
31
- # 39 39 39
32
- # Reading: 0 Writing: 1 Waiting: 0
33
- @keys = %w{active accepted handled requests reading writing waiting}
34
- @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m
35
- end
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
36
10
 
37
- def state(key, value)
38
- if opts.has_key? "#{key}_critical".to_sym
39
- critical_threshold = opts["#{key}_critical".to_sym]
40
- return 'critical' if critical_threshold > 0 and value >= critical_threshold
41
- end
11
+ module Riemann
12
+ module Tools
13
+ class NginxStatus
14
+ include Riemann::Tools
15
+ require 'net/http'
16
+ require 'uri'
42
17
 
43
- if opts.has_key? "#{key}_warning".to_sym
44
- warning_threshold = opts["#{key}_warning".to_sym]
45
- return 'warning' if warning_threshold > 0 and value >= warning_threshold
46
- end
18
+ opt :uri, 'Nginx Stub Status URI', default: 'http://localhost:8080/nginx_status'
19
+ opt :checks, 'Which metrics to report.', type: :strings,
20
+ default: %w[active accepted handled requests reading writing waiting]
21
+ opt :active_warning, 'Active connections warning threshold', default: 0
22
+ opt :active_critical, 'Active connections critical threshold', default: 0
23
+ opt :reading_warning, 'Reading connections warning threshold', default: 0
24
+ opt :reading_critical, 'Reading connections critical threshold', default: 0
25
+ opt :writing_warning, 'Writing connections warning threshold', default: 0
26
+ opt :writing_critical, 'Writing connections critical threshold', default: 0
27
+ opt :waiting_warning, 'Waiting connections warning threshold', default: 0
28
+ opt :waiting_critical, 'Waiting connections critical threshold', default: 0
47
29
 
48
- return 'ok'
49
- end
30
+ def initialize
31
+ @uri = URI.parse(opts[:uri])
50
32
 
51
- def tick
52
- response = nil
53
- begin
54
- response = Net::HTTP.get(@uri)
55
- rescue => e
56
- report(
57
- :service => "nginx health",
58
- :state => "critical",
59
- :description => "Connection error: #{e.class} - #{e.message}"
60
- )
61
- end
33
+ # sample response:
34
+ #
35
+ # Active connections: 1
36
+ # server accepts handled requests
37
+ # 39 39 39
38
+ # Reading: 0 Writing: 1 Waiting: 0
39
+ @keys = %w[active accepted handled requests reading writing waiting]
40
+ @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m
41
+ end
42
+
43
+ def state(key, value)
44
+ if opts.key? "#{key}_critical".to_sym
45
+ critical_threshold = opts["#{key}_critical".to_sym]
46
+ return 'critical' if critical_threshold.positive? && (value >= critical_threshold)
47
+ end
48
+
49
+ if opts.key? "#{key}_warning".to_sym
50
+ warning_threshold = opts["#{key}_warning".to_sym]
51
+ return 'warning' if warning_threshold.positive? && (value >= warning_threshold)
52
+ end
53
+
54
+ 'ok'
55
+ end
56
+
57
+ def tick
58
+ response = nil
59
+ begin
60
+ response = Net::HTTP.get(@uri)
61
+ rescue StandardError => e
62
+ report(
63
+ service: 'nginx health',
64
+ state: 'critical',
65
+ description: "Connection error: #{e.class} - #{e.message}",
66
+ )
67
+ end
62
68
 
63
- return if response.nil?
69
+ return if response.nil?
64
70
 
65
- report(
66
- :service => "nginx health",
67
- :state => "ok",
68
- :description => "Nginx status connection ok"
69
- )
71
+ report(
72
+ service: 'nginx health',
73
+ state: 'ok',
74
+ description: 'Nginx status connection ok',
75
+ )
70
76
 
71
- values = @re.match(response).to_a[1,7].map { |v| v.to_i }
77
+ values = @re.match(response).to_a[1, 7].map(&:to_i)
72
78
 
73
- @keys.zip(values).each do |key, value|
74
- report({
75
- :service => "nginx #{key}",
76
- :metric => value,
77
- :state => state(key, value),
78
- :tags => ['nginx']
79
- })
79
+ @keys.zip(values).each do |key, value|
80
+ report({
81
+ service: "nginx #{key}",
82
+ metric: value,
83
+ state: state(key, value),
84
+ tags: ['nginx'],
85
+ })
86
+ end
87
+ end
80
88
  end
81
89
  end
82
90
  end
data/bin/riemann-ntp CHANGED
@@ -1,38 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- # Reports NTP stats to Riemann.
4
-
5
- require File.expand_path('../../lib/riemann/tools', __FILE__)
6
-
7
- class Riemann::Tools::Ntp
8
- include Riemann::Tools
4
+ Process.setproctitle($PROGRAM_NAME)
9
5
 
10
- def initialize
11
- @hostname = `hostname`.chomp
12
- end
13
-
14
- def tick
15
- stats = `ntpq -p -n`
16
- stats.each_line do |stat|
17
- m = stat.split()
18
- next if m.grep(/^===/).any? || m.grep(/^remote/).any?
19
- @ntp_host = m[0].gsub("*","").gsub("-","").gsub("+","")
20
- send("delay",m[7])
21
- send("offset",m[8])
22
- send("jitter",m[9])
23
- end
24
- end
6
+ # Reports NTP stats to Riemann.
25
7
 
26
- def send(type,metric)
27
- report(
28
- :host => @hostname,
29
- :service => "ntp peer #{@ntp_host} #{type}",
30
- :metric => metric.to_f,
31
- :state => "ok",
32
- :description => "ntp peer #{@ntp_host} #{type}",
33
- :tags => ["ntp"]
34
- )
35
- end
36
- end
8
+ require 'riemann/tools/ntp'
37
9
 
38
10
  Riemann::Tools::Ntp.run
@@ -1,41 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
2
5
 
3
6
  # Checks for open tcp ports.
4
7
  # (c) Max Voit 2017
5
8
 
6
- require File.expand_path('../../lib/riemann/tools', __FILE__)
7
-
8
- class Riemann::Tools::Portcheck
9
- include Riemann::Tools
10
- require 'socket'
11
-
12
- opt :hostname, "Host, defaults to localhost", :default => `hostname`.chomp
13
- opt :ports, "List of ports to check, e.g. '-r 80 443'", :type => :ints
14
-
15
- def initialize
16
- @hostname = opts.fetch(:hostname)
17
- @ports = opts.fetch(:ports)
18
- end
19
-
20
- def tick
21
- for thisport in @ports
22
- # try opening tcp connection with 5s timeout;
23
- # if this fails, the port is considered closed
24
- portopen = Socket.tcp(@hostname, thisport, connect_timeout: 5) { true } rescue false
25
- if portopen
26
- state = "ok"
27
- else
28
- state = "critical"
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
10
+
11
+ module Riemann
12
+ module Tools
13
+ class Portcheck
14
+ include Riemann::Tools
15
+ require 'socket'
16
+
17
+ opt :hostname, 'Host, defaults to localhost', default: `hostname`.chomp
18
+ opt :ports, "List of ports to check, e.g. '-r 80 443'", type: :ints
19
+
20
+ def initialize
21
+ @hostname = opts.fetch(:hostname)
22
+ @ports = opts.fetch(:ports)
23
+ end
24
+
25
+ def tick
26
+ @ports.each do |thisport|
27
+ # try opening tcp connection with 5s timeout;
28
+ # if this fails, the port is considered closed
29
+ portopen = begin
30
+ Socket.tcp(@hostname, thisport, connect_timeout: 5) { true }
31
+ rescue StandardError
32
+ false
33
+ end
34
+ state = if portopen
35
+ 'ok'
36
+ else
37
+ 'critical'
38
+ end
39
+ report(
40
+ host: @hostname.to_s,
41
+ service: "port #{thisport}",
42
+ state: state.to_s,
43
+ tags: ['portcheck'],
44
+ )
29
45
  end
30
- report(
31
- :host => "#{@hostname}",
32
- :service => "port #{thisport}",
33
- :state => "#{state}",
34
- :tags => ["portcheck"]
35
- )
46
+ end
36
47
  end
37
48
  end
38
-
39
49
  end
40
50
 
41
51
  Riemann::Tools::Portcheck.run