nagios_resque 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +37 -0
- data/bin/check_resque +33 -0
- data/lib/nagios_resque/check.rb +57 -0
- data/lib/nagios_resque/job.rb +7 -0
- data/lib/nagios_resque/plugin.rb +75 -0
- data/lib/nagios_resque/version.rb +3 -0
- data/lib/nagios_resque.rb +13 -0
- data/nagios_resque.gemspec +32 -0
- metadata +89 -0
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Nagios plugin for Resque
|
2
|
+
|
3
|
+
It checks resque by putting given job in high queue and expects the job will update key with timestamp.
|
4
|
+
|
5
|
+
```$ check_resque -n 'resque:production' -j 'NagiosResque::Job'
|
6
|
+
|
7
|
+
## Default Job
|
8
|
+
|
9
|
+
Job need update NagiosResque::NAGIOS_RESQUE_TIMESTAMP_KEY key with timestamp.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
module NagiosResque
|
13
|
+
class Job
|
14
|
+
def self.perform
|
15
|
+
Resque.redis.set(NAGIOS_RESQUE_TIMESTAMP_KEY, Time.now.to_i)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
## Options
|
22
|
+
|
23
|
+
```
|
24
|
+
Usage: check_resque [options]
|
25
|
+
-H, --host hosname redis server
|
26
|
+
-p, --port number redis server port
|
27
|
+
-n, --namespace name redis namespace
|
28
|
+
-j, --job name resque job name
|
29
|
+
-k, --key name redis key for timestamp
|
30
|
+
|
31
|
+
Default options:
|
32
|
+
|
33
|
+
-h, --help Display this help.
|
34
|
+
-V, --version Print version.
|
35
|
+
-w, --warn <n:m> Warning threshold.
|
36
|
+
-c, --crit <n:m> Critical threshold.
|
37
|
+
```
|
data/bin/check_resque
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright (c) 2013 Lkhagva Ochirkhuyag
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to
|
8
|
+
# deal in the Software without restriction, including without limitation the
|
9
|
+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
# sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
22
|
+
# IN THE SOFTWARE.
|
23
|
+
#++
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'rubygems'
|
27
|
+
gem 'nagios_resque'
|
28
|
+
rescue LoadError
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'nagios_resque'
|
32
|
+
|
33
|
+
NagiosResque::Plugin.run(*ARGV)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module NagiosResque
|
2
|
+
class Check
|
3
|
+
def initialize(options)
|
4
|
+
@host = options[:host] || "localhost"
|
5
|
+
@port = options[:port] || 6379
|
6
|
+
@namespace = options[:namespace] || "resque"
|
7
|
+
@job = options[:job] || 'NagiosResque::Job'
|
8
|
+
@warning = options[:warn]
|
9
|
+
@critical = options[:crit]
|
10
|
+
|
11
|
+
Resque.redis = "#{@host}:#{@port}/#{@namespace}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def warning?
|
15
|
+
@warning && (passed_time.nil? || @warning.include?(passed_time))
|
16
|
+
end
|
17
|
+
|
18
|
+
def critical?
|
19
|
+
return true unless passed_time
|
20
|
+
@critical && (passed_time.nil? || @critical.first < passed_time)
|
21
|
+
end
|
22
|
+
|
23
|
+
def last_run_at
|
24
|
+
if time = Resque.redis.get(NAGIOS_RESQUE_TIMESTAMP_KEY)
|
25
|
+
Integer(time)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def passed_time
|
30
|
+
# need to cache because there is small time difference between checks
|
31
|
+
return @passed_time if defined?(@passed_time)
|
32
|
+
@passed_time =
|
33
|
+
if time = last_run_at
|
34
|
+
Integer(Time.now - time)
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def requeue
|
41
|
+
Resque::Job.destroy(:high, @job)
|
42
|
+
Resque::Job.create(:high, @job)
|
43
|
+
end
|
44
|
+
|
45
|
+
def ok_message
|
46
|
+
"last run at #{Time.at(last_run_at).strftime('%Y-%m-%d %H:%M:%S %z')}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def warning_message
|
50
|
+
"haven't run in #{@warning.last} seconds"
|
51
|
+
end
|
52
|
+
|
53
|
+
def critical_message
|
54
|
+
"haven't run in #{@critical.first} seconds"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module NagiosResque
|
2
|
+
class Plugin < NagiosPlugin::Plugin
|
3
|
+
include NagiosPlugin::DefaultOptions
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def run(*args)
|
7
|
+
self.new(*args).run
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_options(*args)
|
12
|
+
@options = {}
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.on("-H", "--host hosname", String, "redis server") do |host|
|
15
|
+
@options[:host] = host
|
16
|
+
end
|
17
|
+
opts.on("-p", "--port number", Integer, "redis server port") do |port|
|
18
|
+
@options[:port] = port
|
19
|
+
end
|
20
|
+
opts.on("-n", "--namespace name", String, "redis namespace") do |namespace|
|
21
|
+
@options[:namespace] = namespace
|
22
|
+
end
|
23
|
+
opts.on("-j", "--job name", String, "resque job name") do |job|
|
24
|
+
@options[:job] = job
|
25
|
+
end
|
26
|
+
opts.on("-k", "--key name", String, "redis key for timestamp") do |key|
|
27
|
+
@options[:key] = key
|
28
|
+
end
|
29
|
+
|
30
|
+
yield(opts) if block_given?
|
31
|
+
|
32
|
+
begin
|
33
|
+
opts.parse!(args)
|
34
|
+
|
35
|
+
if @options[:warn].nil? && @options[:crit].nil?
|
36
|
+
@options[:crit] ||= (600..600)
|
37
|
+
end
|
38
|
+
|
39
|
+
if !@options[:warn].nil? && !@options[:crit].nil?
|
40
|
+
if @options[:warn].last > @options[:crit].first
|
41
|
+
unknown "Critical and Warning thresholds shouldn't overlap"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@options
|
45
|
+
rescue => e
|
46
|
+
unknown "#{e}\n\n#{opts}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def service
|
52
|
+
'Resque'
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(*args)
|
56
|
+
parse_options(*args, &default_options)
|
57
|
+
|
58
|
+
@service = Check.new(@options)
|
59
|
+
|
60
|
+
ENV['PATH'] = "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
|
61
|
+
end
|
62
|
+
|
63
|
+
def check
|
64
|
+
if @service.critical?
|
65
|
+
critical @service.critical_message
|
66
|
+
elsif @service.warning?
|
67
|
+
warning @service.warning_message
|
68
|
+
else
|
69
|
+
ok @service.ok_message
|
70
|
+
end
|
71
|
+
ensure
|
72
|
+
@service.requeue
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'resque'
|
2
|
+
require 'nagiosplugin'
|
3
|
+
require 'nagiosplugin/default_options'
|
4
|
+
require 'nagios_resque/version'
|
5
|
+
require 'nagios_resque/job'
|
6
|
+
require 'nagios_resque/check'
|
7
|
+
require 'nagios_resque/plugin'
|
8
|
+
|
9
|
+
module NagiosResque
|
10
|
+
NAGIOS_RESQUE_TIMESTAMP_KEY = 'resque:job:monitor:nagios:time'
|
11
|
+
end
|
12
|
+
|
13
|
+
NagiosPlugin::DefaultOptions::VERSION = NagiosResque::VERSION
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'nagios_resque/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "nagios_resque"
|
9
|
+
|
10
|
+
s.version = NagiosResque::VERSION
|
11
|
+
|
12
|
+
s.homepage = "https://github.com/ochko/nagios_resque"
|
13
|
+
|
14
|
+
s.summary = "Nagios plugin for Resque"
|
15
|
+
|
16
|
+
s.description = <<-EOS
|
17
|
+
A paranoid nagios plugin for checking resque jobs actually being
|
18
|
+
queued, processed in given time. It queues simple job, then later
|
19
|
+
checks if the job is processed and updated timestamp in redis.
|
20
|
+
EOS
|
21
|
+
|
22
|
+
s.authors = ["Lkhagva Ochirkhuyag"]
|
23
|
+
|
24
|
+
s.email = ["ochkoo@gmail.com"]
|
25
|
+
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
|
28
|
+
s.executables = %w[check_resque]
|
29
|
+
|
30
|
+
s.add_dependency('resque')
|
31
|
+
s.add_dependency('nagiosplugin')
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nagios_resque
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lkhagva Ochirkhuyag
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: resque
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nagiosplugin
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! " A paranoid nagios plugin for checking resque jobs actually being\n
|
47
|
+
\ queued, processed in given time. It queues simple job, then later\n checks
|
48
|
+
if the job is processed and updated timestamp in redis.\n"
|
49
|
+
email:
|
50
|
+
- ochkoo@gmail.com
|
51
|
+
executables:
|
52
|
+
- check_resque
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- README.md
|
57
|
+
- bin/check_resque
|
58
|
+
- lib/nagios_resque.rb
|
59
|
+
- lib/nagios_resque/check.rb
|
60
|
+
- lib/nagios_resque/job.rb
|
61
|
+
- lib/nagios_resque/plugin.rb
|
62
|
+
- lib/nagios_resque/version.rb
|
63
|
+
- nagios_resque.gemspec
|
64
|
+
homepage: https://github.com/ochko/nagios_resque
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Nagios plugin for Resque
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|