malevich 0.0.1 → 0.0.2
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/example/cpu.rb +1 -1
- data/example/disk.rb +1 -1
- data/example/disk_stat.rb +5 -5
- data/example/dns_check.rb +2 -2
- data/example/http.rb +1 -1
- data/example/iptables.rb +2 -2
- data/example/la.rb +2 -2
- data/example/mdadm.rb +2 -2
- data/example/megacli.rb +2 -2
- data/example/memory.rb +1 -1
- data/example/net.rb +4 -4
- data/example/net_stat.rb +1 -1
- data/example/nginx.rb +3 -3
- data/example/ntp.rb +1 -1
- data/example/pgsql.rb +3 -3
- data/example/runit.rb +2 -2
- data/example/status_file.rb +1 -1
- data/example/tw_cli.rb +2 -2
- data/lib/malevich/dsl.rb +1 -0
- data/lib/malevich/plugin/event.rb +9 -9
- data/lib/malevich/plugin.rb +3 -3
- data/lib/malevich/responders/http.rb +2 -0
- data/lib/malevich/responders/riemann.rb +2 -2
- data/lib/malevich/version.rb +1 -1
- data/lib/malevich.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e70253bb89c1f108af088c3c442e0ef69049db6e
|
4
|
+
data.tar.gz: ff956877ab483fd1c4e4a0473a92a5d8a9380f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04603ae1935fee81416cc6860c5f288facf3144f79a4d53bc6983a04ccdd7f935f5341f6ad5d65b73749e2d481b17c541c419ed9d73492385534d4511affcc22
|
7
|
+
data.tar.gz: ef094efa3de57927a2b9e0a641b440faea651c67ec2cbec3139a3c44053864f676bf726983f3eb3741bcad9d57635ce2a6f5b41f313e979e5b4e6bb5d46e6eb4
|
data/example/cpu.rb
CHANGED
data/example/disk.rb
CHANGED
data/example/disk_stat.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
always_start true
|
2
2
|
interval 60
|
3
3
|
|
4
|
-
settings :words,
|
4
|
+
settings :words, [ 'reads reqs', 'reads merged', 'reads sector', 'reads time',
|
5
5
|
'writes reqs', 'writes merged', 'writes sector', 'writes time',
|
6
|
-
'io reqs', 'io time', 'io weighted'
|
6
|
+
'io reqs', 'io time', 'io weighted' ]
|
7
7
|
|
8
|
-
settings :filter,
|
8
|
+
settings :filter, [ 'reads reqs', 'writes reqs' ]
|
9
9
|
|
10
|
-
run_if
|
10
|
+
run_if 'linux' do
|
11
11
|
File.exists? '/proc/diskstats'
|
12
12
|
end
|
13
13
|
|
14
|
-
collect
|
14
|
+
collect 'linux' do
|
15
15
|
f = File.read('/proc/diskstats')
|
16
16
|
f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |_, line|
|
17
17
|
if line =~ /^(?:\s+\d+){2}\s+([\w\d]+) (.*)$/
|
data/example/dns_check.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
interval 60
|
2
2
|
|
3
|
-
collect
|
3
|
+
collect 'linux', 'mac_os_x' do
|
4
4
|
event(
|
5
5
|
:state => Resolv::DNS.new.getresources(ohai[:fqdn], Resolv::DNS::Resource::IN::A).count == 1,
|
6
|
-
:description =>
|
6
|
+
:description => 'Check resolv self FQDN')
|
7
7
|
end
|
data/example/http.rb
CHANGED
@@ -10,7 +10,7 @@ settings :insecure, false
|
|
10
10
|
settings :url, 'http://127.0.0.1:80'
|
11
11
|
settings :service, 'http check'
|
12
12
|
|
13
|
-
collect
|
13
|
+
collect 'linux', 'mac_os_x' do
|
14
14
|
|
15
15
|
@cmd ||= begin
|
16
16
|
"curl -X#{settings.http_method} -s --connect-timeout #{settings.connect_timeout}" +
|
data/example/iptables.rb
CHANGED
@@ -2,11 +2,11 @@ interval 60
|
|
2
2
|
settings :rule_file, '/etc/network/iptables'
|
3
3
|
always_start true
|
4
4
|
|
5
|
-
run_if
|
5
|
+
run_if 'linux' do
|
6
6
|
File.exists? settings.rule_file
|
7
7
|
end
|
8
8
|
|
9
|
-
collect
|
9
|
+
collect 'linux' do
|
10
10
|
|
11
11
|
def delete_counters(str)
|
12
12
|
str.gsub(/\[\d+\:\d+\]/, '').strip
|
data/example/la.rb
CHANGED
@@ -4,7 +4,7 @@ interval 60
|
|
4
4
|
state :warning, 4
|
5
5
|
state :critical, 50
|
6
6
|
|
7
|
-
collect
|
7
|
+
collect 'mac_os_x' do
|
8
8
|
event(
|
9
9
|
:metric => shell("sysctl -n vm.loadavg | awk '{print $2}'").to_f,
|
10
10
|
:description => 'LA averaged over 1 minute',
|
@@ -12,7 +12,7 @@ collect "mac_os_x" do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
collect
|
15
|
+
collect 'linux' do
|
16
16
|
event(
|
17
17
|
:metric => File.read('/proc/loadavg').scan(/[\d\.]+/)[0].to_f,
|
18
18
|
:description => 'LA averaged over 1 minute',
|
data/example/mdadm.rb
CHANGED
data/example/megacli.rb
CHANGED
@@ -4,10 +4,10 @@ always_start true
|
|
4
4
|
critical 1
|
5
5
|
settings :cmd, 'megacli -AdpAllInfo -aAll -NoLog | awk -F": " \'/Virtual Drives/ { getline; print $2; }\''
|
6
6
|
|
7
|
-
run_if
|
7
|
+
run_if 'linux' do
|
8
8
|
File.exists? '/usr/bin/megacli'
|
9
9
|
end
|
10
10
|
|
11
|
-
collect
|
11
|
+
collect 'linux' do
|
12
12
|
event(:metric => shell!(settings.cmd).to_i, :description => 'MegaCli status')
|
13
13
|
end
|
data/example/memory.rb
CHANGED
data/example/net.rb
CHANGED
@@ -2,12 +2,12 @@ interval 60
|
|
2
2
|
always_start true
|
3
3
|
|
4
4
|
settings :include_alias, false
|
5
|
-
settings :filter,
|
6
|
-
settings :words,
|
5
|
+
settings :filter, [ 'rx bytes', 'rx errs', 'rx drop', 'tx bytes', 'tx errs', 'tx drop' ]
|
6
|
+
settings :words, [ 'rx bytes', 'rx packets', 'rx errs', 'rx drop', 'rx fifo', 'rx frame',
|
7
7
|
'rx compressed', 'rx multicast', 'tx bytes', 'tx packets', 'tx drops',
|
8
|
-
'tx fifo', 'tx colls', 'tx carrier', 'tx compressed'
|
8
|
+
'tx fifo', 'tx colls', 'tx carrier', 'tx compressed' ]
|
9
9
|
|
10
|
-
collect
|
10
|
+
collect 'linux' do
|
11
11
|
File.read('/proc/net/dev').each_line do |line|
|
12
12
|
iface = line.split(':')[0].strip
|
13
13
|
iface.gsub!(/\./, '_')
|
data/example/net_stat.rb
CHANGED
data/example/nginx.rb
CHANGED
@@ -6,17 +6,17 @@ settings :url, 'http://127.0.0.1:11311/status'
|
|
6
6
|
settings :nginx_status_1, %W(accepts handled requests)
|
7
7
|
settings :nginx_status_2, %W(reading writing waiting)
|
8
8
|
|
9
|
-
run_if
|
9
|
+
run_if 'linux', 'mac_os_x' do
|
10
10
|
File.exists? settings.file
|
11
11
|
end
|
12
12
|
|
13
|
-
collect
|
13
|
+
collect 'linux', 'mac_os_x' do
|
14
14
|
lines = http_get(settings.url).split("\n")
|
15
15
|
lines[2].scan(/\d+/).each_with_index do |value, index|
|
16
16
|
event(:service => "nginx #{settings.nginx_status_1[index]}", :metric => value.to_f/interval, :diff => true)
|
17
17
|
end
|
18
18
|
event(:service => 'nginx active', :metric => lines[0].split(':')[1].strip.to_i)
|
19
19
|
lines[3].scan(/\d+/).each_with_index do |value, index|
|
20
|
-
event(:service =>
|
20
|
+
event(:service => "nginx #{settings.nginx_status_2[index]}", :metric => value.to_i)
|
21
21
|
end
|
22
22
|
end
|
data/example/ntp.rb
CHANGED
data/example/pgsql.rb
CHANGED
@@ -9,11 +9,11 @@ settings :db4monit, 'riemann_monit'
|
|
9
9
|
settings :conn_warn, 5 # reserved pool connections
|
10
10
|
settings :conn_crit, 3 # reserved pool connections
|
11
11
|
|
12
|
-
run_if
|
12
|
+
run_if 'linux' do
|
13
13
|
File.exists? settings.pgsql
|
14
14
|
end
|
15
15
|
|
16
|
-
collect
|
16
|
+
collect 'linux' do
|
17
17
|
|
18
18
|
# helpers
|
19
19
|
def run_sql(sql, db='postgres')
|
@@ -38,7 +38,7 @@ collect "linux" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def repl_lag
|
41
|
-
unixnow - run_sql(
|
41
|
+
unixnow - run_sql('select extract(epoch from value::timestamp) from timestamp where id = 1;', settings.db4monit).to_i
|
42
42
|
end
|
43
43
|
|
44
44
|
def connections
|
data/example/runit.rb
CHANGED
data/example/status_file.rb
CHANGED
data/example/tw_cli.rb
CHANGED
@@ -4,11 +4,11 @@ always_start true
|
|
4
4
|
settings :cmd, "/usr/sbin/tw_cli show | awk '/^c/{print $1}' | xargs -rI{} /usr/sbin/tw_cli /{} show | awk '/^[upb]/&&!/[ \t](OK|VERIFYING|VERIFY-PAUSED)/' |wc -l"
|
5
5
|
critical 1
|
6
6
|
|
7
|
-
run_if
|
7
|
+
run_if 'linux' do
|
8
8
|
File.exists? '/usr/sbin/tw_cli'
|
9
9
|
end
|
10
10
|
|
11
|
-
collect
|
11
|
+
collect 'linux' do
|
12
12
|
event(
|
13
13
|
:service => 'twcli',
|
14
14
|
:metric => shell!(settings.cmd).to_i,
|
data/lib/malevich/dsl.rb
CHANGED
@@ -4,7 +4,7 @@ module Malevich
|
|
4
4
|
def event(hash)
|
5
5
|
event_normalize(hash)
|
6
6
|
hash[:metric] = metric_diff(hash) if hash[:diff]
|
7
|
-
hash[:state]
|
7
|
+
hash[:state] = state_check(hash)
|
8
8
|
if malevich.cmd[:test_given]
|
9
9
|
log :unknown, "Event message from test plugin: #{hash.inspect}"
|
10
10
|
else
|
@@ -14,8 +14,8 @@ module Malevich
|
|
14
14
|
|
15
15
|
def metric_diff(hash)
|
16
16
|
return unless hash[:metric]
|
17
|
-
current_metric
|
18
|
-
old_metric
|
17
|
+
current_metric = hash[:metric]
|
18
|
+
old_metric = histories[hash[:service]] ? histories[hash[:service]][:metric] : nil
|
19
19
|
histories[hash[:service]] = current_metric
|
20
20
|
hash.delete(:diff)
|
21
21
|
old_metric ? current_metric - old_metric : nil
|
@@ -25,7 +25,7 @@ module Malevich
|
|
25
25
|
return hash[:state] if hash[:state]
|
26
26
|
return hash[:state] if hash[:metric].nil?
|
27
27
|
return hash[:state] if hash[:metric].kind_of?(Float) && hash[:metric].nan?
|
28
|
-
warning
|
28
|
+
warning = settings.respond_to?(:warning) ? settings.warning : nil
|
29
29
|
critical = settings.respond_to?(:critical) ? settings.critical : nil
|
30
30
|
return 'ok' if (warning || critical).nil?
|
31
31
|
metric = hash[:metric].to_f
|
@@ -49,12 +49,12 @@ module Malevich
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def event_normalize(hash)
|
52
|
-
hash[:metric]
|
53
|
-
hash[:state]
|
54
|
-
hash[:state]
|
52
|
+
hash[:metric] = hash[:metric].round(2) if hash[:metric].kind_of?(Float)
|
53
|
+
hash[:state] = 'ok' if hash[:state].kind_of?(TrueClass)
|
54
|
+
hash[:state] = 'critical' if hash[:state].kind_of?(FalseClass)
|
55
55
|
hash[:service] ||= name
|
56
|
-
hash[:host]
|
57
|
-
hash[:tags]
|
56
|
+
hash[:host] ||= ohai[:fqdn]
|
57
|
+
hash[:tags] ||= malevich.cmd.tags
|
58
58
|
end
|
59
59
|
|
60
60
|
def event_minimizer(hash)
|
data/lib/malevich/plugin.rb
CHANGED
@@ -18,8 +18,8 @@ module Malevich
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def suitable_platform?(name)
|
21
|
-
|
22
|
-
|
21
|
+
request_platform = name.nil? || name.empty? ? ['linux'] : name
|
22
|
+
request_platform.include?(ohai[:platform]) || request_platform.include?(ohai[:os])
|
23
23
|
end
|
24
24
|
|
25
25
|
def runnable?
|
@@ -29,7 +29,7 @@ module Malevich
|
|
29
29
|
end
|
30
30
|
return log_and_false("'#{name}' not started, because have not 'collect'") if collect.nil?
|
31
31
|
return log_and_false("'#{name}' disabled in config") if settings.disable? && settings.disable
|
32
|
-
return log_and_false("'#{name} disabled by run_if statement
|
32
|
+
return log_and_false("'#{name} disabled by run_if statement") unless !!self.instance_eval(&run_if)
|
33
33
|
log :unknown, "'#{name}' started"
|
34
34
|
end
|
35
35
|
|
@@ -16,6 +16,7 @@ module Malevich
|
|
16
16
|
loop do
|
17
17
|
client = server.accept
|
18
18
|
log :unknown, "Accepted client: #{client.inspect}"
|
19
|
+
|
19
20
|
response = info
|
20
21
|
headers = "HTTP/1.1 200 OK\r\n" +
|
21
22
|
"Server: Malevich Ruby\r\n" +
|
@@ -34,6 +35,7 @@ module Malevich
|
|
34
35
|
:plugins => malevich.monitor.plugins,
|
35
36
|
:monitor => malevich.monitor.tasks.map {|x| { x[1].name => x[0].alive? } },
|
36
37
|
:errors => (malevich.plugins.errors rescue {}),
|
38
|
+
:histories => (malevich.plugins.histories rescue {}),
|
37
39
|
:version => Malevich::VERSION,
|
38
40
|
:ruby => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
|
39
41
|
:uptime => Time.now.to_i - @started_at,
|
@@ -11,7 +11,7 @@ module Malevich
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@riemanns = Array.new
|
14
|
-
@name =
|
14
|
+
@name = 'riemann client'
|
15
15
|
end
|
16
16
|
|
17
17
|
def run!
|
@@ -37,7 +37,7 @@ module Malevich
|
|
37
37
|
client = client.tcp if malevich.cmd['riemann-tcp']
|
38
38
|
log :debug, "Add new riemann client: #{client.host}:#{client.port}"
|
39
39
|
@riemanns << client
|
40
|
-
@name = @riemanns.map {|c| "riemann client [#{c.host}:#{c.port}]" }.join(
|
40
|
+
@name = @riemanns.map {|c| "riemann client [#{c.host}:#{c.port}]" }.join(' , ')
|
41
41
|
end
|
42
42
|
@riemanns
|
43
43
|
end
|
data/lib/malevich/version.rb
CHANGED
data/lib/malevich.rb
CHANGED
@@ -31,15 +31,15 @@ module Malevich
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def ohai
|
34
|
-
if Time.now.to_i - @ohai_timestamp.to_i > 60 * 60
|
34
|
+
if (Time.now.to_i - @ohai_timestamp.to_i > 60 * 60) && !$lock_ohai
|
35
|
+
$lock_ohai = true
|
35
36
|
Kernel::log :info, 'Load ohai data'
|
36
|
-
real_ohai
|
37
|
-
real_ohai.all_plugins
|
37
|
+
@real_ohai ||= Ohai::System.new
|
38
|
+
@real_ohai.all_plugins
|
38
39
|
@ohai_timestamp = Time.now
|
39
|
-
|
40
|
-
else
|
41
|
-
@ohai
|
40
|
+
$lock_ohai = false
|
42
41
|
end
|
42
|
+
@real_ohai.data
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: malevich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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-01-
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: riemann-client
|