riemann-tools 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +15 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.gitignore +2 -0
  6. data/.rubocop.yml +40 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +62 -2
  9. data/README.markdown +8 -24
  10. data/Rakefile +14 -5
  11. data/SECURITY.md +42 -0
  12. data/bin/riemann-apache-status +3 -94
  13. data/bin/riemann-bench +4 -67
  14. data/bin/riemann-cloudant +3 -54
  15. data/bin/riemann-consul +3 -102
  16. data/bin/riemann-dir-files-count +3 -51
  17. data/bin/riemann-dir-space +3 -51
  18. data/bin/riemann-diskstats +3 -91
  19. data/bin/riemann-fd +4 -63
  20. data/bin/riemann-freeswitch +4 -116
  21. data/bin/riemann-haproxy +3 -54
  22. data/bin/riemann-health +3 -344
  23. data/bin/riemann-kvminstance +4 -19
  24. data/bin/riemann-memcached +3 -33
  25. data/bin/riemann-net +3 -105
  26. data/bin/riemann-nginx-status +3 -80
  27. data/bin/riemann-ntp +3 -34
  28. data/bin/riemann-portcheck +3 -37
  29. data/bin/riemann-proc +3 -104
  30. data/bin/riemann-varnish +3 -50
  31. data/bin/riemann-wrapper +75 -0
  32. data/bin/riemann-zookeeper +3 -37
  33. data/lib/riemann/tools/apache_status.rb +107 -0
  34. data/lib/riemann/tools/bench.rb +72 -0
  35. data/lib/riemann/tools/cloudant.rb +57 -0
  36. data/lib/riemann/tools/consul_health.rb +107 -0
  37. data/lib/riemann/tools/dir_files_count.rb +56 -0
  38. data/lib/riemann/tools/dir_space.rb +56 -0
  39. data/lib/riemann/tools/diskstats.rb +94 -0
  40. data/lib/riemann/tools/fd.rb +81 -0
  41. data/lib/riemann/tools/freeswitch.rb +119 -0
  42. data/lib/riemann/tools/haproxy.rb +59 -0
  43. data/lib/riemann/tools/health.rb +478 -0
  44. data/lib/riemann/tools/kvm.rb +23 -0
  45. data/lib/riemann/tools/memcached.rb +38 -0
  46. data/lib/riemann/tools/net.rb +105 -0
  47. data/lib/riemann/tools/nginx_status.rb +86 -0
  48. data/lib/riemann/tools/ntp.rb +42 -0
  49. data/lib/riemann/tools/portcheck.rb +45 -0
  50. data/lib/riemann/tools/proc.rb +109 -0
  51. data/lib/riemann/tools/riemann_client_wrapper.rb +43 -0
  52. data/lib/riemann/tools/uptime_parser.tab.rb +323 -0
  53. data/lib/riemann/tools/varnish.rb +55 -0
  54. data/lib/riemann/tools/version.rb +1 -1
  55. data/lib/riemann/tools/zookeeper.rb +40 -0
  56. data/lib/riemann/tools.rb +31 -52
  57. data/riemann-tools.gemspec +8 -2
  58. data/tools/riemann-aws/{Rakefile.rb → Rakefile} +8 -9
  59. data/tools/riemann-aws/bin/riemann-aws-billing +4 -83
  60. data/tools/riemann-aws/bin/riemann-aws-rds-status +4 -50
  61. data/tools/riemann-aws/bin/riemann-aws-sqs-status +4 -40
  62. data/tools/riemann-aws/bin/riemann-aws-status +4 -67
  63. data/tools/riemann-aws/bin/riemann-elb-metrics +4 -163
  64. data/tools/riemann-aws/bin/riemann-s3-list +4 -78
  65. data/tools/riemann-aws/bin/riemann-s3-status +4 -95
  66. data/tools/riemann-aws/lib/riemann/tools/aws/billing.rb +87 -0
  67. data/tools/riemann-aws/lib/riemann/tools/aws/elb_metrics.rb +163 -0
  68. data/tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb +63 -0
  69. data/tools/riemann-aws/lib/riemann/tools/aws/s3_list.rb +82 -0
  70. data/tools/riemann-aws/lib/riemann/tools/aws/s3_status.rb +97 -0
  71. data/tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb +45 -0
  72. data/tools/riemann-aws/lib/riemann/tools/aws/status.rb +74 -0
  73. data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +8 -9
  74. data/tools/riemann-chronos/bin/riemann-chronos +3 -139
  75. data/tools/riemann-chronos/lib/riemann/tools/chronos.rb +157 -0
  76. data/tools/riemann-docker/{Rakefile.rb → Rakefile} +7 -8
  77. data/tools/riemann-docker/bin/riemann-docker +4 -213
  78. data/tools/riemann-docker/lib/riemann/tools/docker.rb +200 -0
  79. data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +8 -9
  80. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +3 -161
  81. data/tools/riemann-elasticsearch/lib/riemann/tools/elasticsearch.rb +170 -0
  82. data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +8 -9
  83. data/tools/riemann-marathon/bin/riemann-marathon +3 -142
  84. data/tools/riemann-marathon/lib/riemann/tools/marathon.rb +159 -0
  85. data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +8 -9
  86. data/tools/riemann-mesos/bin/riemann-mesos +3 -126
  87. data/tools/riemann-mesos/lib/riemann/tools/mesos.rb +142 -0
  88. data/tools/riemann-munin/{Rakefile.rb → Rakefile} +7 -8
  89. data/tools/riemann-munin/bin/riemann-munin +3 -32
  90. data/tools/riemann-munin/lib/riemann/tools/munin.rb +37 -0
  91. data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +8 -9
  92. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +3 -264
  93. data/tools/riemann-rabbitmq/lib/riemann/tools/rabbitmq.rb +269 -0
  94. data/tools/riemann-riak/{Rakefile.rb → Rakefile} +7 -8
  95. data/tools/riemann-riak/bin/riemann-riak +3 -326
  96. data/tools/riemann-riak/bin/riemann-riak-keys +0 -1
  97. data/tools/riemann-riak/bin/riemann-riak-ring +0 -1
  98. data/tools/riemann-riak/lib/riemann/tools/riak.rb +317 -0
  99. metadata +112 -16
  100. data/.travis.yml +0 -31
  101. data/tools/riemann-riak/riak_status/key_count.erl +0 -13
  102. data/tools/riemann-riak/riak_status/riak_status.rb +0 -152
  103. data/tools/riemann-riak/riak_status/ringready.erl +0 -9
@@ -0,0 +1,269 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ module Riemann
6
+ module Tools
7
+ class Rabbitmq
8
+ include Riemann::Tools
9
+
10
+ require 'faraday'
11
+ require 'json'
12
+ require 'uri'
13
+
14
+ opt :read_timeout, 'Faraday read timeout', type: :int, default: 2
15
+ opt :open_timeout, 'Faraday open timeout', type: :int, default: 1
16
+
17
+ opt :monitor_user, 'RabbitMQ monitoring user', type: :string
18
+ opt :monitor_pass, 'RabbitMQ monitoring user password', type: :string
19
+ opt :monitor_port, 'RabbitMQ monitoring port', type: :int, default: 15_672
20
+ opt :monitor_host, 'RabbitMQ monitoring host', type: :string, default: 'localhost'
21
+ opt :monitor_use_tls, 'RabbitMQ use tls', type: :bool, default: false
22
+
23
+ opt :max_queue_size, 'max number of items in a queue that is acceptable', type: :int, default: 1_000_000
24
+ opt :ignore_max_size_queues, "A regular expression to match queues that shouldn't be size-checked", type: :string
25
+
26
+ opt :node, 'Specify a node to monitor', type: :strings
27
+
28
+ def base_url
29
+ protocol = 'http'
30
+ protocol = 'https' if options[:monitor_use_tls] && (options[:monitor_use_tls] == true)
31
+ "#{protocol}://#{options[:monitor_user]}:#{options[:monitor_pass]}@#{options[:monitor_host]}:#{options[:monitor_port]}/api"
32
+ end
33
+
34
+ def overview_url
35
+ "#{base_url}/overview"
36
+ end
37
+
38
+ def node_url(node)
39
+ "#{base_url}/nodes/#{node}"
40
+ end
41
+
42
+ def queues_url
43
+ "#{base_url}/queues"
44
+ end
45
+
46
+ def event_host
47
+ options[:event_host] || :monitor_host
48
+ end
49
+
50
+ def safe_get(uri, event_host)
51
+ # Handle connection timeouts
52
+ response = nil
53
+ begin
54
+ connection = Faraday.new(uri)
55
+ response = connection.get do |req|
56
+ req.options[:timeout] = options[:read_timeout]
57
+ req.options[:open_timeout] = options[:open_timeout]
58
+ end
59
+ report(
60
+ host: event_host,
61
+ service: 'rabbitmq monitoring',
62
+ state: 'ok',
63
+ description: 'Monitoring operational',
64
+ )
65
+ rescue StandardError => e
66
+ report(
67
+ host: event_host,
68
+ service: 'rabbitmq monitoring',
69
+ state: 'critical',
70
+ description: "HTTP connection error: #{e.class} - #{e.message}",
71
+ )
72
+ end
73
+ response
74
+ end
75
+
76
+ def check_queues
77
+ response = safe_get(queues_url, event_host)
78
+ max_size_check_filter = (Regexp.new(options[:ignore_max_size_queues]) if options[:ignore_max_size_queues])
79
+
80
+ return if response.nil?
81
+
82
+ if response.status != 200
83
+ report(
84
+ host: event_host,
85
+ service: 'rabbitmq.queue',
86
+ state: 'critical',
87
+ description: "HTTP connection error to /api/queues: #{response.status} - #{response.body}",
88
+ )
89
+ else
90
+ report(
91
+ host: event_host,
92
+ service: 'rabbitmq.queue',
93
+ state: 'ok',
94
+ description: 'HTTP connection ok',
95
+ )
96
+
97
+ json = JSON.parse(response.body)
98
+
99
+ json.each do |queue|
100
+ svc = "rabbitmq.queue.#{queue['vhost']}.#{queue['name']}"
101
+ errs = []
102
+
103
+ errs << 'Queue has jobs but no consumers' if !queue['messages_ready'].nil? && (queue['messages_ready']).positive? && (queue['consumers']).zero?
104
+
105
+ errs << "Queue has #{queue['messages_ready']} jobs" if (max_size_check_filter.nil? || queue['name'] !~ (max_size_check_filter)) && !queue['messages_ready'].nil? && (queue['messages_ready'] > options[:max_queue_size])
106
+
107
+ if errs.empty?
108
+ report(
109
+ host: event_host,
110
+ service: svc,
111
+ state: 'ok',
112
+ description: 'Queue is looking good',
113
+ )
114
+ else
115
+ report(
116
+ host: event_host,
117
+ service: svc,
118
+ state: 'critical',
119
+ description: errs.join('; '),
120
+ )
121
+ end
122
+
123
+ stats = (queue['message_stats'] || {}).merge(
124
+ 'messages' => queue['messages'],
125
+ 'messages_details' => queue['messages_details'],
126
+ 'messages_ready' => queue['messages_ready'],
127
+ 'messages_ready_details' => queue['messages_ready_details'],
128
+ 'messages_unacknowledged' => queue['messages_unacknowledged'],
129
+ 'messages_unacknowledged_details' => queue['messages_unacknowledged_details'],
130
+ 'consumers' => queue['consumers'],
131
+ 'memory' => queue['memory'],
132
+ )
133
+
134
+ stats.each_pair do |k, v|
135
+ service = "#{svc}.#{k}"
136
+ metric = if k =~ (/details$/) && !v.nil?
137
+ v['rate']
138
+ else
139
+ v
140
+ end
141
+
142
+ # TODO: Set state via thresholds which can be configured
143
+
144
+ report(
145
+ host: event_host,
146
+ service: service,
147
+ metric: metric,
148
+ description: 'RabbitMQ monitor',
149
+ )
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def check_overview
156
+ uri = URI(overview_url)
157
+ response = safe_get(uri, event_host)
158
+
159
+ return if response.nil?
160
+
161
+ json = JSON.parse(response.body)
162
+
163
+ if response.status != 200
164
+ report(
165
+ host: event_host,
166
+ service: 'rabbitmq',
167
+ state: 'critical',
168
+ description: "HTTP connection error: #{response.status} - #{response.body}",
169
+ )
170
+ else
171
+ report(
172
+ host: event_host,
173
+ service: 'rabbitmq monitoring',
174
+ state: 'ok',
175
+ description: 'HTTP connection ok',
176
+ )
177
+
178
+ %w[message_stats queue_totals object_totals].each do |stat|
179
+ # NOTE: / BUG ?
180
+ # Brand new servers can have blank message stats. Is this ok?
181
+ # I can't decide.
182
+ next if json[stat].empty?
183
+
184
+ json[stat].each_pair do |k, v|
185
+ service = "rabbitmq.#{stat}.#{k}"
186
+ metric = if k =~ /details$/
187
+ v['rate']
188
+ else
189
+ v
190
+ end
191
+
192
+ # TODO: Set state via thresholds which can be configured
193
+
194
+ report(
195
+ host: event_host,
196
+ service: service,
197
+ metric: metric,
198
+ description: 'RabbitMQ monitor',
199
+ )
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ def check_node
206
+ opts[:node].each do |n|
207
+ uri = URI(node_url(n))
208
+ response = safe_get(uri, event_host)
209
+
210
+ break if response.nil?
211
+
212
+ if response.status != 200
213
+ if response.status == 404
214
+ report(
215
+ host: event_host,
216
+ service: "rabbitmq.node.#{n}",
217
+ state: 'critical',
218
+ description: 'Node was not found in the cluster',
219
+ )
220
+ else
221
+ report(
222
+ host: event_host,
223
+ service: "rabbitmq.node.#{n}",
224
+ state: 'critical',
225
+ description: "HTTP error: #{response.status} - #{response.body}",
226
+ )
227
+ end
228
+ break
229
+ end
230
+
231
+ json = JSON.parse(response.body)
232
+
233
+ if json['mem_alarm']
234
+ report(
235
+ host: event_host,
236
+ service: "rabbitmq.node.#{n}",
237
+ state: 'critical',
238
+ description: 'Memory alarm has triggered; job submission throttled',
239
+ )
240
+ break
241
+ end
242
+
243
+ if json['disk_free_alarm']
244
+ report(
245
+ host: event_host,
246
+ service: "rabbitmq.node.#{n}",
247
+ state: 'critical',
248
+ description: 'Disk free alarm has triggered; job submission throttled',
249
+ )
250
+ break
251
+ end
252
+
253
+ report(
254
+ host: event_host,
255
+ service: "rabbitmq.node.#{n}",
256
+ state: 'ok',
257
+ description: 'Node looks OK to me',
258
+ )
259
+ end
260
+ end
261
+
262
+ def tick
263
+ check_overview
264
+ check_node if opts[:node]
265
+ check_queues
266
+ end
267
+ end
268
+ end
269
+ 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'
@@ -9,10 +11,8 @@ ENV['COPYFILE_DISABLE'] = 'true'
9
11
 
10
12
  # Gemspec
11
13
  gemspec = Gem::Specification.new do |s|
12
- s.rubyforge_project = 'riemann-riak'
13
-
14
14
  s.name = 'riemann-riak'
15
- s.version = '0.1.2'
15
+ s.version = '0.1.4'
16
16
  s.author = 'Kyle Kingsbury'
17
17
  s.email = 'aphyr@aphyr.com'
18
18
  s.homepage = 'https://github.com/riemann/riemann-tools'
@@ -20,14 +20,13 @@ gemspec = Gem::Specification.new do |s|
20
20
  s.summary = 'Submits riak stats to riemann.'
21
21
  s.license = 'MIT'
22
22
 
23
- s.add_dependency 'riemann-tools', '>= 0.2.13'
24
- s.add_dependency 'yajl-ruby', '>= 1.1.0'
23
+ s.add_runtime_dependency 'riemann-tools', '~> 1.0', '>= 1.1.1'
24
+ s.add_runtime_dependency 'yajl-ruby', '~> 1.4', '>= 1.4.3'
25
25
 
26
- s.files = FileList['bin/*', 'LICENSE', 'README.md'].to_a
26
+ s.files = FileList['bin/*', 'lib/**/*.rb', 'LICENSE', 'README.md'].to_a
27
27
  s.executables |= Dir.entries('bin/')
28
- s.has_rdoc = false
29
28
 
30
- s.required_ruby_version = '>= 1.8.7'
29
+ s.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
31
30
  end
32
31
 
33
32
  Gem::PackageTask.new gemspec do |p|
@@ -1,331 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
3
 
4
- # Forwards information on a Riak node to Riemann.
4
+ Process.setproctitle($PROGRAM_NAME)
5
5
 
6
- require 'riemann/tools'
7
-
8
- class Riemann::Tools::Riak
9
- include Riemann::Tools
10
- require 'net/http'
11
- require 'net/https'
12
- require 'yajl/json_gem'
13
-
14
- opt :riak_host, "Riak host for stats <IP> or SSL http(s)://<IP>", :default => Socket.gethostname
15
- opt :data_dir, "Riak data directory", :default => '/var/lib/riak'
16
- opt :stats_port, "Riak HTTP port for stats", :default => 8098
17
- opt :stats_path, "Riak HTTP stats path", :default => '/stats'
18
- opt :node_name, "Riak erlang node name", :default => "riak@#{Socket.gethostname}"
19
- opt :cookie, "Riak cookie to use", :default => "riak"
20
-
21
- opt :get_50_warning, "FSM 50% get time warning threshold (ms)", :default => 1000
22
- opt :put_50_warning, "FSM 50% put time warning threshold (ms)", :default => 1000
23
- opt :get_95_warning, "FSM 95% get time warning threshold (ms)", :default => 2000
24
- opt :put_95_warning, "FSM 95% put time warning threshold (ms)", :default => 2000
25
- opt :get_99_warning, "FSM 99% get time warning threshold (ms)", :default => 10000
26
- opt :put_99_warning, "FSM 99% put time warning threshold (ms)", :default => 10000
27
-
28
- def initialize
29
- detect_features
30
-
31
- @httpstatus = true
32
-
33
- begin
34
- uri = URI.parse(opts[:riak_host])
35
- if uri.host == nil
36
- uri.host = opts[:riak_host]
37
- end
38
- http = Net::HTTP.new(uri.host, opts[:stats_port])
39
- http.use_ssl = uri.scheme == 'https'
40
- if http.use_ssl?
41
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
- end
43
- http.start do |h|
44
- h.get opts[:stats_path]
45
- end
46
- rescue => _e
47
- @httpstatus = false
48
- end
49
-
50
- # we're going to override the emulator setting to allow users to
51
- # dynamically input the cookie
52
- # this is done only once - hopefully it doesn't get overridden.
53
- ENV['ERL_AFLAGS'] = "-setcookie #{opts[:cookie]}"
54
- end
55
-
56
- # Identifies whether escript and riak-admin are installed
57
- def detect_features
58
- @escript = true # Whether escript is present on this machine
59
- @riakadmin = true # Whether riak-admin is present
60
-
61
- if `which escript` =~ /^\s*$/
62
- @escript = false
63
- end
64
-
65
- if `which riak-admin` =~ /^\s*$/
66
- @riakadmin = false
67
- end
68
- end
69
-
70
- def check_ring
71
- str = if @escript
72
- str = `#{File.expand_path(File.dirname(__FILE__))}/riemann-riak-ring #{opts[:node_name]}`.chomp
73
- elsif @riakadmin
74
- str = `riak-admin ringready`
75
- else
76
- nil
77
- end
78
-
79
- return if str.nil?
80
-
81
- if str =~ /^TRUE/
82
- report(
83
- :host => opts[:riak_host],
84
- :service => 'riak ring',
85
- :state => 'ok',
86
- :description => str
87
- )
88
- else
89
- report(
90
- :host => opts[:riak_host],
91
- :service => 'riak ring',
92
- :state => 'warning',
93
- :description => str
94
- )
95
- end
96
- end
97
-
98
- def check_keys
99
- keys = `#{File.expand_path(File.dirname(__FILE__))}/riemann-riak-keys #{opts[:node_name]}`.chomp
100
- if keys =~ /^\d+$/
101
- report(
102
- :host => opts[:riak_host],
103
- :service => 'riak keys',
104
- :state => 'ok',
105
- :metric => keys.to_i,
106
- :description => keys
107
- )
108
- else
109
- report(
110
- :host => opts[:riak_host],
111
- :service => 'riak keys',
112
- :state => 'unknown',
113
- :description => keys
114
- )
115
- end
116
- end
117
-
118
- def check_transfers
119
- str = if @riakadmin
120
- `riak-admin transfers`
121
- else
122
- nil
123
- end
124
-
125
- return if str.nil?
126
-
127
- if str =~ /'#{opts[:node_name]}' waiting to handoff (\d+) partitions/
128
- report(
129
- :host => opts[:riak_host],
130
- :service => 'riak transfers',
131
- :state => 'critical',
132
- :metric => $1.to_i,
133
- :description => "waiting to handoff #{$1} partitions"
134
- )
135
- else
136
- report(
137
- :host => opts[:riak_host],
138
- :service => 'riak transfers',
139
- :state => 'ok',
140
- :metric => 0,
141
- :description => "No pending transfers"
142
- )
143
- end
144
- end
145
-
146
- def check_disk
147
- gb = `du -Ls #{opts[:data_dir]}`.split(/\s+/).first.to_i / (1024.0**2)
148
- report(
149
- :host => opts[:riak_host],
150
- :service => 'riak disk',
151
- :state => 'ok',
152
- :metric => gb,
153
- :description => "#{gb} GB in #{opts[:data_dir]}"
154
- )
155
- end
156
-
157
- # Returns the riak stat for the given fsm type and percentile.
158
- def fsm_stat(type, property, percentile)
159
- "node_#{type}_fsm_#{property}_#{percentile == 50 ? 'median' : percentile}"
160
- end
161
-
162
- # Returns the alerts state for the given fsm.
163
- def fsm_state(type, percentile, val)
164
- limit = opts["#{type}_#{percentile}_warning".to_sym]
165
- case val
166
- when 0 .. limit
167
- 'ok'
168
- when limit .. limit * 2
169
- 'warning'
170
- else
171
- 'critical'
172
- end
173
- end
174
-
175
- # Get current stats via HTTP
176
- def stats_http
177
- begin
178
- uri = URI.parse(opts[:riak_host])
179
- if uri.host == nil
180
- uri.host = opts[:riak_host]
181
- end
182
- http = Net::HTTP.new(uri.host, opts[:stats_port])
183
- http.use_ssl = uri.scheme == 'https'
184
- if http.use_ssl?
185
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
186
- end
187
- res = http.start do |h|
188
- h.get opts[:stats_path]
189
- end
190
- rescue => e
191
- report(
192
- :host => opts[:riak_host],
193
- :service => 'riak',
194
- :state => 'critical',
195
- :description => "error fetching #{opts[:riak_host]}:#{opts[:stats_port]} #{e.class}, #{e.message}"
196
- )
197
- raise
198
- end
199
-
200
- if res.code.to_i == 200
201
- return JSON.parse(res.body)
202
- else
203
- report(
204
- :host => opts[:riak_host],
205
- :service => 'riak',
206
- :state => 'critical',
207
- :description => "stats returned HTTP #{res.code}:\n\n#{res.body}"
208
- )
209
- raise "Can't fetch stats via HTTP: #{res.core}:\n\n#{res.body}"
210
- end
211
- end
212
-
213
- # Get current stats via riak-admin
214
- def stats_riak_admin
215
- str = `riak-admin status`
216
- raise "riak-admin failed" unless $? == 0
217
- Hash[str.split(/\n/).map{|i| i.split(/ : /)}]
218
- end
219
-
220
- # Get current stats as a hash
221
- def stats
222
- if @httpstatus
223
- stats_http
224
- elsif @riakadmin
225
- stats_riak_admin
226
- else
227
- report(
228
- :host => opts[:riak_host],
229
- :service => 'riak',
230
- :state => 'critical',
231
- :description => "No mechanism for fetching Riak stats: neither HTTP nor riak-admin available."
232
- )
233
- raise "No mechanism for fetching Riak stats: neither HTTP nor riak-admin available."
234
- end
235
- end
236
-
237
- def core_services
238
- ['vnode_gets',
239
- 'vnode_puts',
240
- 'node_gets',
241
- 'node_puts',
242
- 'node_gets_set',
243
- 'node_puts_set',
244
- 'read_repairs']
245
- end
246
-
247
- def fsm_types
248
- [{'get' => 'time'}, {'put' => 'time'},
249
- {'get' => 'set_objsize'}]
250
- end
251
-
252
- def fsm_percentiles
253
- [50, 95, 99]
254
- end
255
-
256
- # Reports current stats to Riemann
257
- def check_stats
258
- begin
259
- stats = self.stats
260
- rescue => e
261
- event = {:state => 'critical',
262
- :description => e.message,
263
- :host => opts[:riak_host]}
264
- # Report errors
265
- report(event.merge(:service => 'riak'))
266
- core_services.each do |s|
267
- report(event.merge(:service => "riak #{s}"))
268
- end
269
- fsm_types.each do |typespec|
270
- typespec.each do |type, prop|
271
- fsm_percentiles.each do |percentile|
272
- report(event.merge(:service => "riak #{type} #{prop} #{percentile}"))
273
- end
274
- end
275
- end
276
- return
277
- end
278
-
279
- # Riak itself
280
- report(
281
- :host => opts[:riak_host],
282
- :service => 'riak',
283
- :state => 'ok'
284
- )
285
-
286
- # Gets/puts/rr
287
- core_services.each do |s|
288
- report(
289
- :host => opts[:riak_host],
290
- :service => "riak #{s}",
291
- :state => 'ok',
292
- :metric => stats[s].to_i/60.0,
293
- :description => "#{stats[s].to_i/60.0}/sec"
294
- )
295
- end
296
-
297
- # FSMs
298
- fsm_types.each do |typespec|
299
- typespec.each do |type, prop|
300
- fsm_percentiles.each do |percentile|
301
- val = stats[fsm_stat(type, prop, percentile)].to_i || 0
302
- val = 0 if val == 'undefined'
303
- val /= 1000.0 if prop == 'time' # Convert us to ms
304
- if prop == 'time'
305
- state = fsm_state(type, percentile, val)
306
- else
307
- state = "ok"
308
- end
309
- report(
310
- :host => opts[:riak_host],
311
- :service => "riak #{type} #{prop} #{percentile}",
312
- :state => state,
313
- :metric => val,
314
- :description => "#{val} ms"
315
- )
316
- end
317
- end
318
- end
319
- end
320
-
321
- def tick
322
- # This can utterly destroy a cluster, so we disable
323
- # check_keys
324
- check_stats
325
- check_ring
326
- check_disk
327
- check_transfers
328
- end
329
- end
6
+ require 'riemann/tools/riak'
330
7
 
331
8
  Riemann::Tools::Riak.run
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env escript
2
- Process.setproctitle($0)
3
2
  %%! -name riakstatuscheck@127.0.0.1 -hidden
4
3
 
5
4
  main([]) -> main(["riak@127.0.0.1"]);
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env escript
2
- Process.setproctitle($0)
3
2
  %%! -name riakstatuscheck@127.0.0.1 -hidden
4
3
 
5
4
  main([]) -> main(["riak@127.0.0.1"]);