kurchatov 0.0.6.pre.2 → 0.0.6.pre.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/la.rb +1 -0
- data/lib/kurchatov/mixin/event.rb +5 -1
- data/lib/kurchatov/monitor.rb +1 -1
- data/lib/kurchatov/plugin/config.rb +1 -1
- data/lib/kurchatov/plugin.rb +3 -1
- data/lib/kurchatov/queue.rb +7 -1
- data/lib/kurchatov/responders/riemann.rb +1 -1
- data/lib/kurchatov/riemann/event.rb +3 -3
- data/lib/kurchatov/riemann/message.rb +10 -0
- data/lib/kurchatov/version.rb +1 -1
- data/tests/data/config.yml +16 -0
- data/tests/data/event.yml +43 -0
- data/tests/data/sample.rb +12 -0
- data/tests/run.sh +1 -57
- data/tests/server.rb +35 -8
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3567df8dc93294bfc5cb0980d6ba82ebcf22f52
|
4
|
+
data.tar.gz: 9fcd2f6f8c17dbefea266452f832f9d368db34ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea845863682c7b511035e7dbabfebae21f5d8d9e9c4a2e11b1081790a2afef3f09231d1787099b192e6e2258c6149bd79148974e95611e78aae7581d3620974f
|
7
|
+
data.tar.gz: 6ad670d192fddfecb12d62fd5ed5a6b90547e438a3158d7f52c288fd2f233387af1fa3756350a2465e896af805df98cb1acd82fbef16f6bd094a22a0ef37197e
|
data/examples/la.rb
CHANGED
@@ -10,8 +10,9 @@ module Kurchatov
|
|
10
10
|
]
|
11
11
|
|
12
12
|
def event(hash = {})
|
13
|
+
@normilize = normalize_event(hash)
|
13
14
|
Log.info("Mock message for test plugin: #{hash.inspect}") if Kurchatov::Config[:test_plugin]
|
14
|
-
return unless
|
15
|
+
return unless @normilize
|
15
16
|
events << hash
|
16
17
|
end
|
17
18
|
|
@@ -19,10 +20,13 @@ module Kurchatov
|
|
19
20
|
|
20
21
|
def normalize_event(hash = {})
|
21
22
|
hash[:description] = hash[:desc] if hash[:description].nil? && hash[:desc]
|
23
|
+
|
24
|
+
hash[:metric] = hash[:metric].to_f if hash[:metric].kind_of?(String)
|
22
25
|
if hash[:metric].kind_of?(Float)
|
23
26
|
hash[:metric] = 0.0 if hash[:metric].nan?
|
24
27
|
hash[:metric] = hash[:metric].round(2)
|
25
28
|
end
|
29
|
+
|
26
30
|
set_diff_metric(hash)
|
27
31
|
set_event_state(hash)
|
28
32
|
return false if hash[:miss]
|
data/lib/kurchatov/monitor.rb
CHANGED
@@ -17,7 +17,7 @@ module Kurchatov
|
|
17
17
|
@thread.join # call error
|
18
18
|
rescue => e
|
19
19
|
desc = "Plugin '#{@plugin.name}' died. #{e.class}: #{e}\n." +
|
20
|
-
"
|
20
|
+
"Trace: #{e.backtrace.join("\n")}"
|
21
21
|
Log.error(desc)
|
22
22
|
unless @plugin.ignore_errors
|
23
23
|
event(:service => 'riemann client errors', :desc => desc, :state => 'critical')
|
data/lib/kurchatov/plugin.rb
CHANGED
data/lib/kurchatov/queue.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
module Kurchatov
|
4
4
|
class Queue
|
5
5
|
QUEUE_MAX_SIZE = 1_000
|
6
|
+
QUEUE_MAX_FLUSH = 200
|
6
7
|
|
7
8
|
def initialize
|
8
9
|
@events = ::Queue.new
|
@@ -10,16 +11,21 @@ module Kurchatov
|
|
10
11
|
|
11
12
|
def <<(event)
|
12
13
|
if @events.size >= QUEUE_MAX_SIZE
|
14
|
+
# GC start if QUEUE_MAX_SIZE
|
15
|
+
ObjectSpace.garbage_collect
|
13
16
|
drop = @events.shift
|
14
17
|
Log.error("Drop event: #{drop.inspect}. See Kurchatov::Queue::QUEUE_MAX_SIZE")
|
15
18
|
end
|
16
19
|
@events << event
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
22
|
+
def to_flush
|
20
23
|
cur_events = Array.new
|
24
|
+
count = 0
|
21
25
|
until @events.empty?
|
22
26
|
cur_events << @events.shift
|
27
|
+
count += 1
|
28
|
+
break if count > QUEUE_MAX_FLUSH
|
23
29
|
end
|
24
30
|
cur_events
|
25
31
|
end
|
@@ -30,7 +30,7 @@ module Kurchatov
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def flush
|
33
|
-
@events_to_send ||= events.
|
33
|
+
@events_to_send ||= events.to_flush
|
34
34
|
unless @events_to_send.empty?
|
35
35
|
@riemanns.each { |riemann| riemann << @events_to_send }
|
36
36
|
Log.debug("Sended events via #{@name.inspect}: #{@events_to_send}")
|
@@ -4,8 +4,8 @@ module Kurchatov
|
|
4
4
|
include Beefcake::Message
|
5
5
|
optional :time, :int64, 1
|
6
6
|
optional :state, :string, 2
|
7
|
-
|
8
|
-
|
7
|
+
required :service, :string, 3
|
8
|
+
required :host, :string, 4
|
9
9
|
optional :description, :string, 5
|
10
10
|
repeated :tags, :string, 7
|
11
11
|
optional :ttl, :float, 8
|
@@ -26,7 +26,7 @@ module Kurchatov
|
|
26
26
|
def metric
|
27
27
|
metric_d || metric_sint64 || metric_f
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def metric=(m)
|
31
31
|
if Integer === m and (-(2**63)...2**63) === m
|
32
32
|
self.metric_sint64 = m
|
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'beefcake'
|
2
2
|
require 'kurchatov/riemann/event'
|
3
3
|
|
4
|
+
# monkey patch
|
5
|
+
module Beefcake::Message
|
6
|
+
def initialize(attrs={})
|
7
|
+
attrs ||= {}
|
8
|
+
fields.values.each do |fld|
|
9
|
+
self[fld.name] = attrs[fld.name]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
module Kurchatov
|
5
15
|
module Riemann
|
6
16
|
class Message
|
data/lib/kurchatov/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
not_exists:
|
2
|
+
- not error please
|
3
|
+
|
4
|
+
# create sample_plugin from sample
|
5
|
+
sample_plugin:
|
6
|
+
cmd: 'ls'
|
7
|
+
url: 'http://example.com'
|
8
|
+
parent: sample
|
9
|
+
sleep: 2
|
10
|
+
|
11
|
+
# cteate sample_0 and sample_1
|
12
|
+
sample:
|
13
|
+
- url: 'http://google.com'
|
14
|
+
cmd: 'test -f ./tests/run.sh'
|
15
|
+
- url: 'https://www.kernel.org'
|
16
|
+
cmd: 'ps'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
events:
|
2
|
+
|
3
|
+
- :metric: 3
|
4
|
+
:critical: 2
|
5
|
+
:warning: 1
|
6
|
+
:result: critical
|
7
|
+
:service: metric > critical
|
8
|
+
|
9
|
+
- :metric: 2
|
10
|
+
:critical: 2
|
11
|
+
:warning: 1
|
12
|
+
:result: critical
|
13
|
+
:service: metric == critical
|
14
|
+
|
15
|
+
- :metric: 1
|
16
|
+
:critical: 2
|
17
|
+
:warning: 1
|
18
|
+
:result: warning
|
19
|
+
:service: metric == warning
|
20
|
+
|
21
|
+
- :metric: 0
|
22
|
+
:critical: 2
|
23
|
+
:warning: 1
|
24
|
+
:result: ok
|
25
|
+
:service: metric < warning
|
26
|
+
|
27
|
+
- :state: true
|
28
|
+
:result: ok
|
29
|
+
:service: state TrueClass
|
30
|
+
|
31
|
+
- :state: false
|
32
|
+
:result: critical
|
33
|
+
:service: state FalseClass
|
34
|
+
|
35
|
+
- :eval: 'shell("ls /| wc -l | wc -l")'
|
36
|
+
:warning: 0
|
37
|
+
:result: warning
|
38
|
+
:service: Shell test
|
39
|
+
|
40
|
+
- :eval: 'rest_get("http://ya.ru").size'
|
41
|
+
:critical: 10
|
42
|
+
:result: critical
|
43
|
+
:service: Http get test
|
@@ -0,0 +1,12 @@
|
|
1
|
+
name "sample"
|
2
|
+
always_start true
|
3
|
+
|
4
|
+
collect do
|
5
|
+
data = YAML.load_file('./tests/data/event.yml')
|
6
|
+
data["events"].each do |e|
|
7
|
+
e[:metric] = eval(e[:eval]) if e.has_key? :eval
|
8
|
+
event(e)
|
9
|
+
end
|
10
|
+
sleep(plugin.sleep.to_f || 0)
|
11
|
+
exit 0 if plugin.sleep
|
12
|
+
end
|
data/tests/run.sh
CHANGED
@@ -1,59 +1,3 @@
|
|
1
1
|
#!/bin/sh -e
|
2
|
-
|
3
|
-
|
4
2
|
bundle exec ruby ./tests/server.rb &
|
5
|
-
|
6
|
-
rm -rf ./tmp
|
7
|
-
mkdir -p ./tmp
|
8
|
-
cat > tmp/config.yml <<EOF
|
9
|
-
not_exists:
|
10
|
-
- not error please
|
11
|
-
test2:
|
12
|
-
url: './tests/run.sh'
|
13
|
-
cmd: 'ls'
|
14
|
-
parent: 'test'
|
15
|
-
counter: 2
|
16
|
-
test:
|
17
|
-
- url: 'http://google.com'
|
18
|
-
cmd: 'test -f ./tests/run.sh'
|
19
|
-
- url: 'https://www.kernel.org'
|
20
|
-
cmd: 'ps'
|
21
|
-
EOF
|
22
|
-
|
23
|
-
cat > tmp/test1.rb <<EOF
|
24
|
-
interval 10
|
25
|
-
name "test"
|
26
|
-
|
27
|
-
default[:url] = 'http://notexists'
|
28
|
-
default[:cmd] = 'ls /notexists'
|
29
|
-
|
30
|
-
collect do
|
31
|
-
@counter ||= 0
|
32
|
-
Log.info "file command #{plugin.cmd} return: #{shell(plugin.cmd)}"
|
33
|
-
Log.info "get size from #{plugin.url}: #{rest_get(plugin.url).size}"
|
34
|
-
@counter += 1
|
35
|
-
exit 0 if plugin.counter && @counter > plugin.counter.to_i
|
36
|
-
event(:metric => 3, :critical => 2, :warning => 1)
|
37
|
-
event(:metric => 2, :critical => 2, :warning => 1)
|
38
|
-
event(:metric => 1, :critical => 2, :warning => 1)
|
39
|
-
event(:metric => 0, :critical => 2, :warning => 1)
|
40
|
-
end
|
41
|
-
EOF
|
42
|
-
|
43
|
-
# --test-plugin
|
44
|
-
bundle exec ./bin/kurchatov --test-plugin ./tmp/test1.rb --logfile ./tmp/testplugin.log -l debug || echo "Mock error in 'ls /notexists'"
|
45
|
-
echo "Stdout --test-plugin:"
|
46
|
-
cat ./tmp/testplugin.log
|
47
|
-
grep -q 'STDERR: ls: cannot access /notexists' ./tmp/testplugin.log
|
48
|
-
|
49
|
-
# load config and helpers
|
50
|
-
bundle exec ./bin/kurchatov -d ./tmp/ -c ./tmp/config.yml --hosts 127.0.0.1 -l debug --stop-on-error --logfile ./tmp/loadplugins.log
|
51
|
-
echo "Stdout loader"
|
52
|
-
cat ./tmp/loadplugins.log
|
53
|
-
grep 'Start plugins' ./tmp/loadplugins.log | grep -q '@name="test_0"'
|
54
|
-
grep 'Start plugins' ./tmp/loadplugins.log | grep -q '@name="test_1"'
|
55
|
-
grep 'Start plugins' ./tmp/loadplugins.log | grep -q '@name="test2"'
|
56
|
-
grep 'file command ls return: CHANGELOG' ./tmp/loadplugins.log
|
57
|
-
grep 'get size from http://google.com:' ./tmp/loadplugins.log
|
58
|
-
grep 'get size from https://www.kernel.org' ./tmp/loadplugins.log
|
59
|
-
grep 'get size from ./tests/run.sh' ./tmp/loadplugins.log
|
3
|
+
bundle exec kurchatov -c ./tests/data/config.yml -d ./tests/data -H 127.0.0.1 --stop-on-error
|
data/tests/server.rb
CHANGED
@@ -1,11 +1,38 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'timeout'
|
3
|
+
require 'kurchatov/riemann/client'
|
4
|
+
require 'yaml'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
PORT = 5555
|
7
|
+
HOST = '127.0.0.1'
|
8
|
+
RECEIVE_INTERVAL = 20
|
9
|
+
|
10
|
+
server = TCPServer.new(HOST, PORT)
|
11
|
+
events = []
|
12
|
+
puts "Run riemann server at #{HOST}:#{PORT}"
|
13
|
+
|
14
|
+
Timeout::timeout(RECEIVE_INTERVAL) {
|
15
|
+
client = server.accept
|
16
|
+
loop do
|
17
|
+
line = client.read(4)
|
18
|
+
break if line.nil? || line.size != 4
|
19
|
+
length = line.unpack('N').first
|
20
|
+
str = client.read(length)
|
21
|
+
message = Kurchatov::Riemann::Message.decode(str)
|
22
|
+
message.events.each do |event|
|
23
|
+
events << event
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
data = YAML.load_file('./tests/data/event.yml')
|
29
|
+
events.each do |e|
|
30
|
+
data["events"].each do |d|
|
31
|
+
next unless d[:service] == e[:service]
|
32
|
+
next if d[:result] == e[:state]
|
33
|
+
raise "Recieved state: #{e[:state]}, data state: #{d[:result]}. \n Data: #{d.inspect} \n Event: #{e.inspect}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
raise "Not all events recieved" unless 3 * data["events"].count == events.count
|
38
|
+
puts "All done!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kurchatov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.pre.
|
4
|
+
version: 0.0.6.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliev Dmitry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: beefcake
|
@@ -200,6 +200,9 @@ files:
|
|
200
200
|
- lib/ohai/plugins/windows/cpu.rb
|
201
201
|
- lib/ohai/plugins/windows/hostname.rb
|
202
202
|
- lib/ohai/plugins/windows/platform.rb
|
203
|
+
- tests/data/config.yml
|
204
|
+
- tests/data/event.yml
|
205
|
+
- tests/data/sample.rb
|
203
206
|
- tests/run.sh
|
204
207
|
- tests/server.rb
|
205
208
|
homepage: https://github.com/vadv/kurchatov
|