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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1b68e4d209f800c0c2a08ce6166a01fe4c3f9dd
4
- data.tar.gz: 0a28fab3e6992d1a6f29b2cc88c4bb3d020fd566
3
+ metadata.gz: e70253bb89c1f108af088c3c442e0ef69049db6e
4
+ data.tar.gz: ff956877ab483fd1c4e4a0473a92a5d8a9380f12
5
5
  SHA512:
6
- metadata.gz: d724ea316def8f81ea864a15a240dce95eb0adc2bcf3498317d8eab48b0cdafc7b0ac0da99500a0754875e37e4e07c452924ef8296bb05f155812fc09c7eb696
7
- data.tar.gz: 04f3e20dcc6334742a56494c9618c331d0c2b91337dece4ddf29af2d0981d3987888abb63c4146c3c53d67660f7f8e03736691350fbe5894e765f8f53cd1a838
6
+ metadata.gz: 04603ae1935fee81416cc6860c5f288facf3144f79a4d53bc6983a04ccdd7f935f5341f6ad5d65b73749e2d481b17c541c419ed9d73492385534d4511affcc22
7
+ data.tar.gz: ef094efa3de57927a2b9e0a641b440faea651c67ec2cbec3139a3c44053864f676bf726983f3eb3741bcad9d57635ce2a6f5b41f313e979e5b4e6bb5d46e6eb4
data/example/cpu.rb CHANGED
@@ -5,7 +5,7 @@ critical 85
5
5
 
6
6
  settings :per_process, false
7
7
 
8
- collect "linux" do
8
+ collect 'linux' do
9
9
  @old_cpu ||= {}
10
10
  File.read('/proc/stat').each_line do |cpu_line|
11
11
  cpu_number = cpu_line.scan(/cpu(\d+|\s)\s+/)
data/example/disk.rb CHANGED
@@ -12,7 +12,7 @@ settings :not_monit_device_4_fstab, %w(none)
12
12
  settings :not_monit_point_4_fstab, %w(/lib/init/rw /dev/shm /dev)
13
13
  settings :check_fstab, true
14
14
 
15
- collect "linux" do
15
+ collect 'linux' do
16
16
 
17
17
  def get_monit_points_for_size
18
18
  monit_points = []
data/example/disk_stat.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  always_start true
2
2
  interval 60
3
3
 
4
- settings :words, %w( 'reads reqs', 'reads merged', 'reads sector', 'reads time',
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, %w('reads reqs', 'writes reqs')
8
+ settings :filter, [ 'reads reqs', 'writes reqs' ]
9
9
 
10
- run_if "linux" do
10
+ run_if 'linux' do
11
11
  File.exists? '/proc/diskstats'
12
12
  end
13
13
 
14
- collect "linux" do
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 "linux", "mac_os_x" do
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 => "Check resolv self FQDN")
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 "linux", "mac_os_x" do
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 "linux" do
5
+ run_if 'linux' do
6
6
  File.exists? settings.rule_file
7
7
  end
8
8
 
9
- collect "linux" do
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 "mac_os_x" do
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 "linux" do
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
@@ -1,11 +1,11 @@
1
1
  interval 60
2
2
  critical 1
3
3
 
4
- run_if "linux" do
4
+ run_if 'linux' do
5
5
  File.exists? '/proc/mdstat'
6
6
  end
7
7
 
8
- collect "linux" do
8
+ collect 'linux' do
9
9
 
10
10
  def rm_bracket(text)
11
11
  text.gsub('[', '').gsub(']', '')
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 "linux" do
7
+ run_if 'linux' do
8
8
  File.exists? '/usr/bin/megacli'
9
9
  end
10
10
 
11
- collect "linux" do
11
+ collect 'linux' do
12
12
  event(:metric => shell!(settings.cmd).to_i, :description => 'MegaCli status')
13
13
  end
data/example/memory.rb CHANGED
@@ -4,7 +4,7 @@ always_start true
4
4
  critical 70
5
5
  warning 85
6
6
 
7
- collect "linux" do
7
+ collect 'linux' do
8
8
  m = File.read('/proc/meminfo').split(/\n/).inject({}) do |info, line|
9
9
  x = line.split(/:?\s+/)
10
10
  info[x[0]] = x[1].to_i
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, %W('rx bytes', 'rx errs', 'rx drop', 'tx bytes', 'tx errs', 'tx drop')
6
- settings :words, %W('rx bytes', 'rx packets', 'rx errs', 'rx drop', 'rx fifo', 'rx frame',
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 "linux" do
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
@@ -1,7 +1,7 @@
1
1
  interval 5
2
2
  settings :ports, [80, 3994]
3
3
 
4
- collect "linux" do
4
+ collect 'linux' do
5
5
 
6
6
  filter = nil
7
7
  settings.ports.each do |port|
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 "linux", "mac_os_x" do
9
+ run_if 'linux', 'mac_os_x' do
10
10
  File.exists? settings.file
11
11
  end
12
12
 
13
- collect "linux", "mac_os_x" do
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 => plugin.service + " #{settings.nginx_status_2[index]}", :metric => value.to_i)
20
+ event(:service => "nginx #{settings.nginx_status_2[index]}", :metric => value.to_i)
21
21
  end
22
22
  end
data/example/ntp.rb CHANGED
@@ -6,7 +6,7 @@ critical 10
6
6
  settings :host, 'pool.ntp.org'
7
7
  settings :timeout, 30
8
8
 
9
- collect "linux", "mac_os_x" do
9
+ collect 'linux', 'mac_os_x' do
10
10
  event(
11
11
  :service => "ntp #{settings.host}",
12
12
  :description => "Ntp lag with host #{settings.host}",
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 "linux" do
12
+ run_if 'linux' do
13
13
  File.exists? settings.pgsql
14
14
  end
15
15
 
16
- collect "linux" do
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("select extract(epoch from value::timestamp) from timestamp where id = 1;", settings.db4monit).to_i
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
@@ -1,11 +1,11 @@
1
1
  interval 60
2
2
  always_start true
3
3
 
4
- run_if "linux" do
4
+ run_if 'linux' do
5
5
  Dir.exists? '/etc/service'
6
6
  end
7
7
 
8
- collect "linux" do
8
+ collect 'linux' do
9
9
 
10
10
  @status_history ||= Array.new
11
11
 
@@ -7,7 +7,7 @@ settings :service, 'check state file'
7
7
 
8
8
  critical 1
9
9
 
10
- collect "linux" do
10
+ collect 'linux' do
11
11
  content = File.read(settings.file).split("\n").delete_if { |x| x.strip.empty? }
12
12
  event(
13
13
  :service => "#{settings.service} #{settings.file}",
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 "linux" do
7
+ run_if 'linux' do
8
8
  File.exists? '/usr/sbin/tw_cli'
9
9
  end
10
10
 
11
- collect "linux" do
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
@@ -70,6 +70,7 @@ module Malevich
70
70
 
71
71
  def self.test(file)
72
72
  dsl = Malevich::DSL.new
73
+ dsl.plugins << Malevich::Plugin.new(File.basename(file, PLUGIN_EXT))
73
74
  dsl.instance_eval(File.read(file), file)
74
75
  dsl.plugins[0]
75
76
  end
@@ -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] = state_check(hash)
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 = hash[:metric]
18
- old_metric = histories[hash[:service]]
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 = settings.respond_to?(:warning) ? settings.warning : nil
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] = 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)
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] ||= ohai[:fqdn]
57
- hash[:tags] ||= malevich.cmd.tags
56
+ hash[:host] ||= ohai[:fqdn]
57
+ hash[:tags] ||= malevich.cmd.tags
58
58
  end
59
59
 
60
60
  def event_minimizer(hash)
@@ -18,8 +18,8 @@ module Malevich
18
18
  end
19
19
 
20
20
  def suitable_platform?(name)
21
- platforms = name.nil? || name.empty? ? ['linux'] : name
22
- platforms.include?(ohai[:platform]) || platforms.include?(ohai[:os])
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'") unless !!self.instance_eval(&run_if)
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 = "riemann client"
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
@@ -1,3 +1,3 @@
1
1
  module Malevich
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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 = Ohai::System.new
37
- real_ohai.all_plugins
37
+ @real_ohai ||= Ohai::System.new
38
+ @real_ohai.all_plugins
38
39
  @ohai_timestamp = Time.now
39
- @ohai = real_ohai.data
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.1
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-12 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-client