watchmonkey_cli 1.5 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/README.md +4 -4
- data/VERSION +1 -1
- data/doc/checker_example.rb +67 -0
- data/doc/config_example.rb +45 -0
- data/lib/watchmonkey_cli/checkers/unix_load.rb +7 -0
- data/lib/watchmonkey_cli/hooks/requeue.rb +28 -13
- data/lib/watchmonkey_cli/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e8b3281a2641174927f13de6f09d0bf2c35988
|
4
|
+
data.tar.gz: 1dbd8ec4d401dae1651fae131a874381242365f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41cffe415bdb00af10d9ee99ce1a5a59db0f9fa989c2938eefb329c378f4b16687774713946a82b02e4b44c23f6a48187f942ed96ace18a992f235ea58935ba1
|
7
|
+
data.tar.gz: 6be8aa148f2a41b3a4766e34ed02f9192d6591aa7486c49250190adced0e3546b1dfb4b7b898a098741d82ff089622541743ab4ddb4d8104c4933741c3d552c1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -68,21 +68,21 @@ If you want to deactivate single configs just rename the file to start with two
|
|
68
68
|
|
69
69
|
|
70
70
|
## Application configuration
|
71
|
-
If you want to add custom checkers, hooks or change default settings you can create `~/.watchmonkey/config.rb`. The file will be eval'd in the application object's context. Take a look at the [example configuration file](https://github.com/2called-chaos/watchmonkey_cli/blob/master/
|
71
|
+
If you want to add custom checkers, hooks or change default settings you can create `~/.watchmonkey/config.rb`. The file will be eval'd in the application object's context. Take a look at the [example configuration file](https://github.com/2called-chaos/watchmonkey_cli/blob/master/doc/config_example.rb) and [application.rb](https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/application.rb).
|
72
72
|
|
73
73
|
|
74
74
|
## Custom checkers
|
75
|
-
If you want to monitor something that is not covered by the buildin handlers you can create your own, it's not that hard and should be a breeze if you are used to Ruby. All descendants of the `WatchmonkeyCli::Checker` class will be initialized and are usable in the application. Documentation is thin but you can take a look at the [example checker](https://github.com/2called-chaos/watchmonkey_cli/blob/master/
|
75
|
+
If you want to monitor something that is not covered by the buildin handlers you can create your own, it's not that hard and should be a breeze if you are used to Ruby. All descendants of the `WatchmonkeyCli::Checker` class will be initialized and are usable in the application. Documentation is thin but you can take a look at the [example checker](https://github.com/2called-chaos/watchmonkey_cli/blob/master/doc/checker_example.rb), the [buildin checkers](https://github.com/2called-chaos/watchmonkey_cli/tree/master/lib/watchmonkey_cli/checkers) or just [open an issue](https://github.com/2called-chaos/watchmonkey_cli/issues/new) and I might just implement it real quick.
|
76
76
|
|
77
77
|
|
78
78
|
## Additional Features
|
79
79
|
|
80
80
|
### ReQueue
|
81
81
|
By default Watchmonkey will run all tests once and then exit. This addon will enable Watchmonkey to run in a loop and run tests on a periodic interval.
|
82
|
-
Since this seems like a core feature it might get included directly into Watchmonkey but for now take a look at the
|
82
|
+
Since this seems like a core feature it might get included directly into Watchmonkey but for now take a look at the [application configuration file](https://github.com/2called-chaos/watchmonkey_cli/blob/master/doc/config_example.rb) and [ReQueue source code](https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/hooks/requeue.rb) for integration examples.
|
83
83
|
|
84
84
|
### Platypus support
|
85
|
-
[Platypus](http://sveinbjorn.org/platypus) is a MacOS software to create dead simple GUI wrappers for scripts. There is buildin support for the interface types ProgressBar and WebView. For
|
85
|
+
[Platypus](http://sveinbjorn.org/platypus) is a MacOS software to create dead simple GUI wrappers for scripts. There is buildin support for the interface types ProgressBar and WebView. For integration examples take a look at the [application configuration file](https://github.com/2called-chaos/watchmonkey_cli/blob/master/doc/config_example.rb) and [Platypus hook source code](https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/hooks/platypus.rb).
|
86
86
|
|
87
87
|
|
88
88
|
## Contributing
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# You will need to place this file somewhere and require it in your
|
2
|
+
# `~/.watchmonkey/config.rb` in order for it to register in the application.
|
3
|
+
# You can also place it into `~/watchmonkey/checkers/` and it will get required
|
4
|
+
# automatically unless the file name starts with two underscores.
|
5
|
+
|
6
|
+
module MyWatchmonkeyCheckers
|
7
|
+
class MyChecker < WatchmonkeyCli::Checker
|
8
|
+
# ============
|
9
|
+
# = Required =
|
10
|
+
# ============
|
11
|
+
# This name defines how you can add tests in your configs.
|
12
|
+
# e.g. my_checker "http://google.com", some_option: true
|
13
|
+
self.checker_name = "my_checker"
|
14
|
+
|
15
|
+
# Called by configuration defining a check with all the arguments.
|
16
|
+
# e.g. my_checker "http://google.com", some_option: true
|
17
|
+
# Should invoke `app.enqueue` which will by default call `#check!` method with given arguments.
|
18
|
+
def enqueue host, opts = {}
|
19
|
+
opts = { some_option: false }.merge(opts)
|
20
|
+
|
21
|
+
# If you want to exec commands (locally or SSH) usually a connection or symbol is passed.
|
22
|
+
# The buildin handlers follow this logic:
|
23
|
+
host = app.fetch_connection(:loopback, :local) if !host || host == :local
|
24
|
+
host = app.fetch_connection(:ssh, host) if host.is_a?(Symbol)
|
25
|
+
|
26
|
+
# requires first argument to be self (the checker), all other arguments are passed to `#check!` method.
|
27
|
+
app.enqueue(self, host, opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
# First argument is the result object, all other arguments came from `app.enqueue` call.
|
31
|
+
def check! result, host, opts = {}
|
32
|
+
# Do your checks and modify the result object.
|
33
|
+
# Debug messages will not show if -s/--silent or -q/--quiet argument is passed.
|
34
|
+
# Info messages will not show if -q/-quiet argument is passed.
|
35
|
+
|
36
|
+
result.error "foo" # add error message (type won't be changed)
|
37
|
+
result.error! "foo" # add error message (type changes to error)
|
38
|
+
result.info "foo"
|
39
|
+
result.info! "foo"
|
40
|
+
result.debug "foo"
|
41
|
+
result.debug! "foo"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
# ============
|
47
|
+
# = Optional =
|
48
|
+
# ============
|
49
|
+
def init
|
50
|
+
# hook method (called when checker is being initialized)
|
51
|
+
end
|
52
|
+
|
53
|
+
def start
|
54
|
+
# hook method (called after all checkers were initialized and configs + hosts are loaded)
|
55
|
+
# can/should be used for starting connections, etc.
|
56
|
+
end
|
57
|
+
|
58
|
+
def stop
|
59
|
+
# hook method (called on application shutdown)
|
60
|
+
# connections should be closed here
|
61
|
+
|
62
|
+
# DO NOT CLOSE CONNECTIONS HANDLED BY THE APP!
|
63
|
+
# Keep in mind that the checkers run concurrently
|
64
|
+
# and therefore shared resources might still be in use
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Create this file as ~/.watchmonkey/config.rb
|
2
|
+
# This file is eval'd in the application object's context after it's initialized!
|
3
|
+
|
4
|
+
# Change option defaults (arguments will still override these settings)
|
5
|
+
# For options refer to application.rb#initialize
|
6
|
+
# https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/application.rb
|
7
|
+
@opts[:threads] = 50
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
# Integrate ReQueue (module for infinite checking)
|
12
|
+
# For options refer to the source code:
|
13
|
+
# https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/hooks/requeue.rb
|
14
|
+
if @argv.delete("--requeue") || @argv.delete("--reQ")
|
15
|
+
require "watchmonkey_cli/hooks/requeue"
|
16
|
+
WatchmonkeyCli::Requeue.hook!(self)
|
17
|
+
|
18
|
+
# change options after hooking!
|
19
|
+
@opts[:threads] = 8 # don't need as many here because speed is not a concern
|
20
|
+
@opts[:default_requeue] = 60 # default delay before requeuing checker, override with `every: 10.minutes` checker option
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# Integrate Platypus (module for MacOS tool Platypus)
|
26
|
+
# For options refer to the source code:
|
27
|
+
# https://github.com/2called-chaos/watchmonkey_cli/blob/master/lib/watchmonkey_cli/hooks/platypus.rb
|
28
|
+
if @argv.delete("--platypus")
|
29
|
+
require "watchmonkey_cli/hooks/platypus"
|
30
|
+
|
31
|
+
# Options:
|
32
|
+
# * notifications(1)
|
33
|
+
# 1 - silent notifications (OS X notifications)
|
34
|
+
# 2 - notifications with sound (OS X notifications)
|
35
|
+
# everything else disables notifications (and renders the hook somewhat useless)
|
36
|
+
# * progress(true)
|
37
|
+
# outputs "PROGRESS:##" for Platypus ProgressBar interface (useless if HTML is enabled)
|
38
|
+
# * html(false)
|
39
|
+
# outputs HTML for Platypus WebView interface
|
40
|
+
# * draw_delay(1)
|
41
|
+
# seconds between HTML updates (useless if HTML is disabled)
|
42
|
+
WatchmonkeyCli::Platypus.hook!(self, notifications: 1, html: true, draw_delay: 3)
|
43
|
+
|
44
|
+
@opts[:colorize] = false # doesn't render in platypus
|
45
|
+
end
|
@@ -20,6 +20,13 @@ module WatchmonkeyCli
|
|
20
20
|
emsg << "load5 is to high (limit5 is #{opts[:limits][1]}, load5 is #{ld[1]})" if ld[1] > opts[:limits][1]
|
21
21
|
emsg << "load15 is to high (limit15 is #{opts[:limits][2]}, load15 is #{ld[2]})" if ld[2] > opts[:limits][2]
|
22
22
|
result.error!(emsg.join("\n\t")) if emsg.any?
|
23
|
+
|
24
|
+
# plotter support
|
25
|
+
app.fire :plotter_push, self, host, {
|
26
|
+
load1: ld[0], limit1: opts[:limits][0],
|
27
|
+
load5: ld[1], limit5: opts[:limits][1],
|
28
|
+
load15: ld[2], limit15: opts[:limits][2],
|
29
|
+
}
|
23
30
|
end
|
24
31
|
|
25
32
|
def _parse_response res
|
@@ -2,10 +2,15 @@ module WatchmonkeyCli
|
|
2
2
|
class Requeue
|
3
3
|
def self.hook!(app)
|
4
4
|
app.instance_eval do
|
5
|
+
@requeue = []
|
6
|
+
|
5
7
|
# app options
|
6
8
|
@opts[:loop_forever] = true
|
7
9
|
@opts[:logfile] = logger_filename # enable logging
|
8
10
|
|
11
|
+
# scheduler options
|
12
|
+
@opts[:requeue_scheduler_hibernation] = 1 # tickrate of schedule in seconds
|
13
|
+
|
9
14
|
# module options
|
10
15
|
@opts[:default_requeue] = 60
|
11
16
|
# @opts[:default_requeue_ftp_availability] = 60
|
@@ -19,9 +24,6 @@ module WatchmonkeyCli
|
|
19
24
|
# @opts[:default_requeue_unix_memory] = 60
|
20
25
|
@opts[:default_requeue_www_availability] = 30
|
21
26
|
|
22
|
-
# Requeue threads
|
23
|
-
@requeue = []
|
24
|
-
|
25
27
|
|
26
28
|
# =================
|
27
29
|
# = Status thread =
|
@@ -45,6 +47,25 @@ module WatchmonkeyCli
|
|
45
47
|
end
|
46
48
|
|
47
49
|
|
50
|
+
# =================
|
51
|
+
# = Scheduler thread =
|
52
|
+
# =================
|
53
|
+
@requeue_scheduler_thread = Thread.new do
|
54
|
+
Thread.current.abort_on_exception = true
|
55
|
+
loop do
|
56
|
+
break if $wm_runtime_exiting
|
57
|
+
sync do
|
58
|
+
@requeue.each_with_index do |(run_at, callback), index|
|
59
|
+
next if run_at > Time.now
|
60
|
+
callback.call()
|
61
|
+
@requeue.delete_at(index)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
sleep @opts[:requeue_scheduler_hibernation]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
48
69
|
# =========
|
49
70
|
# = Hooks =
|
50
71
|
# =========
|
@@ -61,11 +82,8 @@ module WatchmonkeyCli
|
|
61
82
|
|
62
83
|
hook :wm_shutdown do
|
63
84
|
sync do
|
64
|
-
|
65
|
-
|
66
|
-
@requeue.each(&:kill).each(&:join).select!(&:alive?)
|
67
|
-
debug "[ReQ] #{@requeue.length} items in requeue..."
|
68
|
-
end
|
85
|
+
@requeue_scheduler_thread.try(:join)
|
86
|
+
debug "[ReQ] Clearing #{@requeue.length} items in requeue..."
|
69
87
|
@requeue_status_thread.try(:kill).try(:join)
|
70
88
|
end
|
71
89
|
end
|
@@ -77,12 +95,9 @@ module WatchmonkeyCli
|
|
77
95
|
def requeue checker, args, delay = 10
|
78
96
|
return if $wm_runtime_exiting
|
79
97
|
sync do
|
80
|
-
@requeue <<
|
81
|
-
Thread.current.abort_on_exception = true
|
82
|
-
sleep(delay)
|
98
|
+
@requeue << [Time.now + delay, ->{
|
83
99
|
checker.enqueue(*args)
|
84
|
-
|
85
|
-
}
|
100
|
+
}]
|
86
101
|
end
|
87
102
|
end
|
88
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watchmonkey_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Pachnit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -112,6 +112,8 @@ files:
|
|
112
112
|
- VERSION
|
113
113
|
- bin/watchmonkey
|
114
114
|
- bin/watchmonkey.sh
|
115
|
+
- doc/checker_example.rb
|
116
|
+
- doc/config_example.rb
|
115
117
|
- lib/watchmonkey_cli.rb
|
116
118
|
- lib/watchmonkey_cli/application.rb
|
117
119
|
- lib/watchmonkey_cli/application/colorize.rb
|