riemann-tools 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'rubygems/package_task'
3
5
  require 'rdoc/task'
@@ -1,140 +1,157 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
3
 
4
- require 'riemann/tools'
5
-
6
- class Riemann::Tools::Chronos
7
- include Riemann::Tools
8
-
9
- require 'faraday'
10
- require 'json'
11
- require 'uri'
4
+ Process.setproctitle($PROGRAM_NAME)
12
5
 
13
- opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
14
- opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
15
- opt :path_prefix, 'Chronos path prefix for proxied installations e.g. "chronos" for target http://localhost/chronos/metrics', default: "/"
16
- opt :chronos_host, 'Chronos host', default: "localhost"
17
- opt :chronos_port, 'Chronos port', type: :int, default: 4400
6
+ require 'riemann/tools'
18
7
 
19
- def initialize
20
- options[:interval] = 60
21
- options[:ttl] = 120
22
- end
8
+ module Riemann
9
+ module Tools
10
+ class Chronos
11
+ include Riemann::Tools
12
+
13
+ require 'faraday'
14
+ require 'json'
15
+ require 'uri'
16
+
17
+ opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
18
+ opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
19
+ opt :path_prefix,
20
+ 'Chronos path prefix for proxied installations e.g. "chronos" for target http://localhost/chronos/metrics', default: '/'
21
+ opt :chronos_host, 'Chronos host', default: 'localhost'
22
+ opt :chronos_port, 'Chronos port', type: :int, default: 4400
23
+
24
+ def initialize
25
+ options[:interval] = 60
26
+ options[:ttl] = 120
27
+ end
23
28
 
24
- # Handles HTTP connections and GET requests safely
25
- def safe_get(uri)
26
- # Handle connection timeouts
27
- response = nil
28
- begin
29
- connection = Faraday.new(uri)
30
- response = connection.get do |req|
31
- req.options[:timeout] = options[:read_timeout]
32
- req.options[:open_timeout] = options[:open_timeout]
29
+ # Handles HTTP connections and GET requests safely
30
+ def safe_get(uri)
31
+ # Handle connection timeouts
32
+ response = nil
33
+ begin
34
+ connection = Faraday.new(uri)
35
+ response = connection.get do |req|
36
+ req.options[:timeout] = options[:read_timeout]
37
+ req.options[:open_timeout] = options[:open_timeout]
38
+ end
39
+ rescue StandardError => e
40
+ report(
41
+ host: uri.host,
42
+ service: 'chronos health',
43
+ state: 'critical',
44
+ description: "HTTP connection error: #{e.class} - #{e.message}",
45
+ )
33
46
  end
34
- rescue => e
35
- report(:host => uri.host,
36
- :service => "chronos health",
37
- :state => "critical",
38
- :description => "HTTP connection error: #{e.class} - #{e.message}"
39
- )
47
+ response
40
48
  end
41
- response
42
- end
43
49
 
44
- def health_url
45
- path_prefix = options[:path_prefix]
46
- path_prefix[0] = '' if path_prefix[0]=='/'
47
- path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
48
- "http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/metrics"
49
- end
50
+ def health_url
51
+ path_prefix = options[:path_prefix]
52
+ path_prefix[0] = '' if path_prefix[0] == '/'
53
+ path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
54
+ "http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/metrics"
55
+ end
50
56
 
51
- def jobs_url
52
- path_prefix = options[:path_prefix]
53
- path_prefix[0] = '' if path_prefix[0]=='/'
54
- path_prefix[path_prefix.length-1] = '' if path_prefix[path_prefix.length-1]=='/'
55
- "http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length>0?'/':''}#{path_prefix}/scheduler/jobs"
56
- end
57
+ def jobs_url
58
+ path_prefix = options[:path_prefix]
59
+ path_prefix[0] = '' if path_prefix[0] == '/'
60
+ path_prefix[path_prefix.length - 1] = '' if path_prefix[path_prefix.length - 1] == '/'
61
+ "http://#{options[:chronos_host]}:#{options[:chronos_port]}#{path_prefix.length.positive? ? '/' : ''}#{path_prefix}/scheduler/jobs"
62
+ end
57
63
 
58
- def tick
59
- tick_health
60
- tick_jobs
61
- end
64
+ def tick
65
+ tick_health
66
+ tick_jobs
67
+ end
68
+
69
+ def tick_health
70
+ uri = URI(health_url)
71
+ response = safe_get(uri)
72
+
73
+ return if response.nil?
74
+
75
+ if response.status != 200
76
+ report(
77
+ host: uri.host,
78
+ service: 'chronos health',
79
+ state: 'critical',
80
+ description: "HTTP connection error: #{response.status} - #{response.body}",
81
+ )
82
+ else
83
+ # Assuming that a 200 will give json
84
+ json = JSON.parse(response.body)
85
+
86
+ report(
87
+ host: uri.host,
88
+ service: 'chronos health',
89
+ state: 'ok',
90
+ )
91
+
92
+ json.each_pair do |t, d|
93
+ next unless d.respond_to? :each_pair
94
+
95
+ d.each_pair do |service, counters|
96
+ report(
97
+ host: uri.host,
98
+ service: "chronos_metric #{t} #{service}",
99
+ metric: 1,
100
+ tags: ['metric_name'],
101
+ ttl: 600,
102
+ )
103
+ next unless counters.respond_to? :each_pair
62
104
 
63
- def tick_health
64
- uri = URI(health_url)
65
- response = safe_get(uri)
66
-
67
- return if response.nil?
68
-
69
- if response.status != 200
70
- report(:host => uri.host,
71
- :service => "chronos health",
72
- :state => "critical",
73
- :description => "HTTP connection error: #{response.status} - #{response.body}"
74
- )
75
- else
76
- # Assuming that a 200 will give json
77
- json = JSON.parse(response.body)
78
-
79
- report(:host => uri.host,
80
- :service => "chronos health",
81
- :state => "ok")
82
-
83
- json.each_pair do |t, d|
84
- if d.respond_to? :each_pair
85
- d.each_pair do |service, counters|
86
- report(:host => uri.host,
87
- :service => "chronos_metric #{t} #{service}",
88
- :metric => 1,
89
- :tags => ["metric_name"],
90
- :ttl => 600
91
- )
92
- if counters.respond_to? :each_pair
93
105
  counters.each_pair do |k, v|
94
- if v.is_a? Numeric
95
- report(:host => uri.host,
96
- :service => "chronos #{service} #{k}",
97
- :metric => v,
98
- :tags => ["metric", "#{t}"],
99
- :ttl => 600
100
- )
101
- end
106
+ next unless v.is_a? Numeric
107
+
108
+ report(
109
+ host: uri.host,
110
+ service: "chronos #{service} #{k}",
111
+ metric: v,
112
+ tags: ['metric', t.to_s],
113
+ ttl: 600,
114
+ )
102
115
  end
103
116
  end
104
117
  end
105
118
  end
106
119
  end
107
- end
108
- end
109
120
 
110
- def tick_jobs
111
- uri = URI(jobs_url)
112
- response = safe_get(uri)
113
-
114
- return if response.nil?
115
-
116
- if response.status != 200
117
- report(:host => uri.host,
118
- :service => "chronos health",
119
- :state => "critical",
120
- :description => "HTTP connection error: #{response.status} - #{response.body}"
121
- )
122
- else
123
- # Assuming that a 200 will give json
124
- json = JSON.parse(response.body)
125
-
126
- report(:host => uri.host,
127
- :service => "chronos health",
128
- :state => "ok")
129
-
130
- json.each do |job|
131
- job.each_pair do |k, v|
132
- if v.is_a? Numeric
133
- report(:host => uri.host,
134
- :service => "chronos job #{job["name"]} #{k}",
135
- :metric => v,
136
- :ttl => 120
137
- )
121
+ def tick_jobs
122
+ uri = URI(jobs_url)
123
+ response = safe_get(uri)
124
+
125
+ return if response.nil?
126
+
127
+ if response.status != 200
128
+ report(
129
+ host: uri.host,
130
+ service: 'chronos health',
131
+ state: 'critical',
132
+ description: "HTTP connection error: #{response.status} - #{response.body}",
133
+ )
134
+ else
135
+ # Assuming that a 200 will give json
136
+ json = JSON.parse(response.body)
137
+
138
+ report(
139
+ host: uri.host,
140
+ service: 'chronos health',
141
+ state: 'ok',
142
+ )
143
+
144
+ json.each do |job|
145
+ job.each_pair do |k, v|
146
+ next unless v.is_a? Numeric
147
+
148
+ report(
149
+ host: uri.host,
150
+ service: "chronos job #{job['name']} #{k}",
151
+ metric: v,
152
+ ttl: 120,
153
+ )
154
+ end
138
155
  end
139
156
  end
140
157
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'rubygems/package_task'
3
5
  require 'rdoc/task'