kurchatov 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kurchatov/mixin/event.rb +45 -8
- data/lib/kurchatov/version.rb +1 -1
- data/tests/data/event.yml +54 -3
- data/tests/data/sample.rb +3 -3
- data/tests/server.rb +3 -11
- data/tests/testreceived.rb +36 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9094918f08537775203d52e22d3669276a8e3cee
|
4
|
+
data.tar.gz: d775c33d9a51f5e5fa5e87a0fef7a874218e5657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bdf806068549afe1a9f2519ef954effe5561b1ecda9acde8179c7aa210484168de07bb21a503690fc97b4eea2ad46f40ed6fda8c692585b29ff21ac6c7d0857
|
7
|
+
data.tar.gz: d6f752f13bc30d1c65707462e078566fe527f3661128551286b0c1ea2bec911c65e288f15dbb509bbd3317bc9329f39b3ed697df653a109433a26078b7b39a68
|
@@ -5,8 +5,8 @@ module Kurchatov
|
|
5
5
|
include Kurchatov::Mixin::Queue
|
6
6
|
|
7
7
|
EVENT_FIELDS = [
|
8
|
-
|
9
|
-
|
8
|
+
:time, :state, :service, :host,
|
9
|
+
:description, :tags, :ttl, :metric
|
10
10
|
]
|
11
11
|
|
12
12
|
def event(hash = {})
|
@@ -19,15 +19,22 @@ module Kurchatov
|
|
19
19
|
protected
|
20
20
|
|
21
21
|
def normalize_event(hash = {})
|
22
|
+
|
22
23
|
hash[:description] = hash[:desc] if hash[:description].nil? && hash[:desc]
|
23
24
|
hash[:metric] = hash[:metric].to_f if hash[:metric].kind_of?(String)
|
24
25
|
if hash[:metric].kind_of?(Float)
|
25
26
|
hash[:metric] = 0.0 if hash[:metric].nan?
|
26
27
|
hash[:metric] = ((hash[:metric] * 100).round/100.to_f) # 1.8.7 round
|
27
28
|
end
|
29
|
+
|
28
30
|
set_diff_metric(hash)
|
31
|
+
set_bool_metric(hash)
|
32
|
+
set_bool_state(hash)
|
33
|
+
set_avg_metric(hash)
|
29
34
|
set_event_state(hash)
|
35
|
+
|
30
36
|
return false if hash[:miss]
|
37
|
+
|
31
38
|
hash.each { |k, _| hash.delete(k) unless EVENT_FIELDS.include?(k) }
|
32
39
|
hash[:service] ||= name
|
33
40
|
hash[:tags] ||= Kurchatov::Config[:tags]
|
@@ -36,10 +43,6 @@ module Kurchatov
|
|
36
43
|
end
|
37
44
|
|
38
45
|
def set_event_state(hash = {})
|
39
|
-
if hash[:state] == true || hash[:state] == false
|
40
|
-
hash[:state] = hash[:state] ? 'ok' : 'critical'
|
41
|
-
return
|
42
|
-
end
|
43
46
|
return if hash[:state]
|
44
47
|
return if hash[:critical].nil? && hash[:warning].nil?
|
45
48
|
return if hash[:metric].nil?
|
@@ -49,23 +52,57 @@ module Kurchatov
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def set_diff_metric(hash ={})
|
55
|
+
|
52
56
|
hash[:diff] ||= hash[:as_diff] if hash[:as_diff]
|
57
|
+
|
53
58
|
return if hash[:diff].nil? && !hash[:diff]
|
54
59
|
return if hash[:metric].nil?
|
55
60
|
return if hash[:service].nil?
|
56
|
-
hash[:metric] = 0 if hash[:metric] == false
|
57
|
-
hash[:metric] = 1 if hash[:metric] == true
|
58
61
|
@history ||= {}
|
62
|
+
|
59
63
|
if @history[hash[:service]]
|
60
64
|
old_metric = @history[hash[:service]]
|
61
65
|
@history[hash[:service]] = hash[:metric]
|
62
66
|
hash[:metric] = hash[:metric] - old_metric
|
63
67
|
else
|
64
68
|
@history[hash[:service]] = hash[:metric]
|
69
|
+
hash[:metric] = nil
|
65
70
|
hash[:miss] = true
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
74
|
+
def set_bool_metric(hash ={})
|
75
|
+
hash[:metric] = 0 if hash[:metric] == false
|
76
|
+
hash[:metric] = 1 if hash[:metric] == true
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_bool_state(hash ={})
|
80
|
+
if hash[:state] == true || hash[:state] == false
|
81
|
+
hash[:state] = hash[:state] ? 'ok' : 'critical'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_avg_metric(hash ={})
|
86
|
+
|
87
|
+
return if hash[:avg].nil? || hash[:avg].to_i != hash[:avg]
|
88
|
+
return if hash[:service].nil?
|
89
|
+
return if hash[:metric].nil?
|
90
|
+
|
91
|
+
@history_avg ||= {}
|
92
|
+
@history_avg[hash[:service]] ||= []
|
93
|
+
@history_avg[hash[:service]] << hash[:metric].to_f
|
94
|
+
@history_avg[hash[:service]] = @history_avg[hash[:service]].last(hash[:avg])
|
95
|
+
|
96
|
+
return if hash[:miss]
|
97
|
+
|
98
|
+
if @history_avg[hash[:service]].count >= (hash[:avg] / 2) + 1
|
99
|
+
hash[:metric] = @history_avg[hash[:service]].reduce(:+).to_f / @history_avg[hash[:service]].count
|
100
|
+
else
|
101
|
+
hash[:miss] = true
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
69
106
|
end
|
70
107
|
end
|
71
108
|
end
|
data/lib/kurchatov/version.rb
CHANGED
data/tests/data/event.yml
CHANGED
@@ -32,17 +32,17 @@ events:
|
|
32
32
|
:result: critical
|
33
33
|
:service: state FalseClass
|
34
34
|
|
35
|
-
- :
|
35
|
+
- :eval_metric: 'shell("ls /| wc -l | wc -l")'
|
36
36
|
:warning: 0
|
37
37
|
:result: warning
|
38
38
|
:service: Shell test
|
39
39
|
|
40
|
-
- :
|
40
|
+
- :eval_metric: 'rest_get("http://ya.ru").size'
|
41
41
|
:critical: 10
|
42
42
|
:result: critical
|
43
43
|
:service: Http get test
|
44
44
|
|
45
|
-
- :
|
45
|
+
- :eval_metric: 'rest_get("http://127.0.0.1:55755").size'
|
46
46
|
:critical: 1
|
47
47
|
:result: critical
|
48
48
|
:service: Http responder
|
@@ -52,3 +52,54 @@ events:
|
|
52
52
|
:warning: 1
|
53
53
|
:result: ok
|
54
54
|
:service: round float
|
55
|
+
|
56
|
+
- :metric: 1.5
|
57
|
+
:critical: 2
|
58
|
+
:warning: 1
|
59
|
+
:avg: 2
|
60
|
+
:service: avg
|
61
|
+
:time: 1
|
62
|
+
:miss_count: true # only for tests
|
63
|
+
|
64
|
+
- :metric: 0.6
|
65
|
+
:result: warning # avg == 2, (1.5 + 0.6)/2 >= 1
|
66
|
+
:critical: 2
|
67
|
+
:warning: 1
|
68
|
+
:avg: 2
|
69
|
+
:service: avg
|
70
|
+
:time: 2
|
71
|
+
|
72
|
+
- :metric: 10
|
73
|
+
:result: critical # avg == 2, (10 + 0.6)/2 >= critical
|
74
|
+
:critical: 2
|
75
|
+
:warning: 1
|
76
|
+
:avg: 2
|
77
|
+
:service: avg
|
78
|
+
:time: 3
|
79
|
+
|
80
|
+
- :metric: 10
|
81
|
+
:critical: 2
|
82
|
+
:warning: 1
|
83
|
+
:avg: 2
|
84
|
+
:diff: true
|
85
|
+
:service: avg with diff
|
86
|
+
:time: 4
|
87
|
+
:miss_count: true
|
88
|
+
|
89
|
+
- :metric: 12
|
90
|
+
:critical: 2
|
91
|
+
:warning: 1
|
92
|
+
:avg: 2
|
93
|
+
:diff: true
|
94
|
+
:service: avg with diff
|
95
|
+
:time: 5
|
96
|
+
:miss_count: true
|
97
|
+
|
98
|
+
- :metric: 14.5
|
99
|
+
:critical: 2
|
100
|
+
:warning: 1
|
101
|
+
:avg: 2
|
102
|
+
:diff: true
|
103
|
+
:service: avg with diff
|
104
|
+
:result: critical
|
105
|
+
:time: 6
|
data/tests/data/sample.rb
CHANGED
@@ -4,9 +4,9 @@ always_start true
|
|
4
4
|
collect do
|
5
5
|
data = YAML.load_file('./tests/data/event.yml')
|
6
6
|
data["events"].each do |e|
|
7
|
-
e[:metric] = eval(e[:
|
7
|
+
e[:metric] = eval(e[:eval_metric]) if e.has_key? :eval_metric
|
8
8
|
event(e)
|
9
9
|
end
|
10
|
-
sleep(plugin.sleep.to_f
|
11
|
-
exit 0 if plugin.sleep
|
10
|
+
sleep(plugin.sleep.to_f)
|
11
|
+
exit 0 if plugin.sleep # 1 plugin send exit 0
|
12
12
|
end
|
data/tests/server.rb
CHANGED
@@ -2,6 +2,7 @@ require 'socket'
|
|
2
2
|
require 'timeout'
|
3
3
|
require 'kurchatov/riemann/client'
|
4
4
|
require 'yaml'
|
5
|
+
require_relative 'testreceived'
|
5
6
|
|
6
7
|
PORT = 5555
|
7
8
|
HOST = '127.0.0.1'
|
@@ -25,14 +26,5 @@ Timeout::timeout(RECEIVE_INTERVAL) {
|
|
25
26
|
end
|
26
27
|
}
|
27
28
|
|
28
|
-
|
29
|
-
|
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!"
|
29
|
+
t = TestReceived.new(events, './tests/data/event.yml')
|
30
|
+
t.compare!
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class TestReceived
|
2
|
+
|
3
|
+
def initialize(events, file)
|
4
|
+
@events = events
|
5
|
+
@file = file
|
6
|
+
end
|
7
|
+
|
8
|
+
def data
|
9
|
+
@data ||= YAML.load_file(@file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def compare!
|
13
|
+
|
14
|
+
@events.each do |e|
|
15
|
+
data["events"].each do |d|
|
16
|
+
next unless d[:service] == e[:service]
|
17
|
+
next if d[:result] == e[:state]
|
18
|
+
next if d[:time] && d[:time] != e[:time]
|
19
|
+
raise "Recieved state: #{e[:state].inspect}, data state: #{d[:result].inspect}. \n Data: #{d.inspect} \n Event: #{e.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
from_data = data["events"].select {|x| x[:miss_count] != true }.count
|
24
|
+
from_events = @events.count
|
25
|
+
|
26
|
+
raise "Not all events recieved: from data: #{from_data} and from server: #{from_events}" unless 3 * from_data == from_events # see config.yml (3 copy of sample plugin run)
|
27
|
+
|
28
|
+
puts "Recieved events:"
|
29
|
+
puts "#{@events.inspect}"
|
30
|
+
puts "Sample data:"
|
31
|
+
puts "#{data.inspect}"
|
32
|
+
|
33
|
+
puts "All done!"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
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.2.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: beefcake
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- tests/data/sample.rb
|
198
198
|
- tests/run.sh
|
199
199
|
- tests/server.rb
|
200
|
+
- tests/testreceived.rb
|
200
201
|
homepage: https://github.com/vadv/kurchatov
|
201
202
|
licenses:
|
202
203
|
- MIT
|