riemann-babbler 0.3.3 → 0.3.4

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.
data/config.yml CHANGED
@@ -12,7 +12,7 @@ plugins:
12
12
  interval: 1
13
13
 
14
14
  la:
15
- service: la la_1
15
+ service: la
16
16
  interval: 1
17
17
  states:
18
18
  warning: 4
@@ -33,10 +33,8 @@ module Riemann
33
33
  alias :opts :options
34
34
 
35
35
  def report(event)
36
- case event[:metric]
37
- when Hash
38
- report_with_diff(event) and return
39
- end
36
+ report_with_diff(event) and return if event[:is_diff]
37
+ event[:state] = state(event[:metric]) unless plugin.states.critical.nil?
40
38
  event[:tags] = options.riemann.tags unless options.riemann.tags.nil?
41
39
  event[:host] = host
42
40
  logger.debug "Report status: #{event.inspect}"
@@ -44,11 +42,10 @@ module Riemann
44
42
  end
45
43
 
46
44
  def report_with_diff(event)
47
- current_metric = event[:metric][:value]
48
- event[:metric][:value] = current_metric - @storage[ event[:service] ] if @storage.has_key? event[:service]
45
+ current_metric = event[:metric]
46
+ event[:metric] = current_metric - @storage[ event[:service] ] if @storage.has_key? event[:service]
49
47
  @storage[ event[:service] ] = current_metric
50
- event[:state] = state(current_metric) unless plugin.states.critical.nil?
51
- event[:metric] = event[:metric][:value]
48
+ event.delete(:is_diff)
52
49
  report(event)
53
50
  end
54
51
 
@@ -93,8 +90,7 @@ module Riemann
93
90
  begin
94
91
  tick
95
92
  rescue => e
96
- #report({:service => plugin.service, :status => 'critical'})
97
- $stderr.puts "#{e.class} #{e}\n#{e.backtrace.join "\n"}"
93
+ logger.error "Plugin #{self.class.name} : #{e.class} #{e}\n#{e.backtrace.join "\n"}"
98
94
  end
99
95
 
100
96
  sleep(plugin.interval - ((Time.now - t0) % plugin.interval))
@@ -103,13 +99,9 @@ module Riemann
103
99
 
104
100
  # Переодически вызываемое действие
105
101
  def tick
106
- posted_hash = collect
107
- posted_hash.each_key do |service|
108
- report({
109
- :service => service,
110
- :metric => posted_hash[service][:metric]
111
- })
112
- end
102
+ posted_array = collect
103
+ posted_array = posted_array.class == Array ? posted_array : [ posted_array ]
104
+ posted_array.each { |event| report event }
113
105
  end
114
106
 
115
107
  # Доступ к конфигу определенного плагина
@@ -13,7 +13,7 @@ class Riemann::Babbler::Cpu < Riemann::Babbler
13
13
  end
14
14
 
15
15
  @old_cpu = [u2, n2, s2, i2]
16
- {"cpu" => fraction}
16
+ {:service => plugin.service, :metric => fraction}
17
17
  end
18
18
 
19
19
  end
@@ -12,11 +12,7 @@ class Riemann::Babbler::Disk < Riemann::Babbler
12
12
  'devtmpfs'
13
13
  ]
14
14
 
15
- def plugin
16
- options.plugins.disk
17
- end
18
-
19
- def disk
15
+ def collect
20
16
  # собираем только необходимые для мониторинга маунт-поинты
21
17
  # точнее выбираем из mounts только те, у которых fstype не попадает
22
18
  # в NOT_MONITORING_FS
@@ -25,26 +21,15 @@ class Riemann::Babbler::Disk < Riemann::Babbler
25
21
  mtab = line.split(/\s+/)
26
22
  monit_points << mtab[1] unless NOT_MONITORING_FS.include? mtab[2]
27
23
  end
28
- disk = Hash.new
24
+ disk = Array.new
29
25
  monit_points.each do |point|
30
26
  point_stat = Filesystem.stat point
31
27
  human_point = point == "/" ? "/root" : point
32
- human_point.gsub!(/^\//, "")
33
- human_point.gsub!(/\//, "_")
34
- disk.merge!({human_point + " block" => 1 - point_stat.blocks_available.to_f/point_stat.blocks})
35
- disk.merge!({human_point + " inode" => 1 - point_stat.files_available.to_f/point_stat.files})
28
+ human_point.gsub!(/^\//, "").gsub!(/\//, "_")
29
+ disk << { :service => human_point + " block", :metric => 1 - point_stat.blocks_available.to_f/point_stat.blocks }
30
+ disk << { :service => human_point + " inode", :metric => 1 - point_stat.files_available.to_f/point_stat.files }
36
31
  end
37
32
  disk
38
33
  end
39
34
 
40
- def tick
41
- disk.each do |point, free|
42
- report({
43
- :service => plugin.service + " #{point}",
44
- :state => state(free),
45
- :metric => free
46
- })
47
- end
48
- end
49
-
50
35
  end
@@ -1,10 +1,7 @@
1
1
  class Riemann::Babbler::Dummy < Riemann::Babbler
2
2
 
3
3
  def collect
4
- {
5
- :service => plugin.service,
6
- :state => 'ok'
7
- }
4
+ { :service => plugin.service , :state => 'ok' }
8
5
  end
9
6
 
10
7
  end
@@ -1,9 +1,7 @@
1
1
  class Riemann::Babbler::La < Riemann::Babbler
2
2
 
3
3
  def collect
4
- {
5
- "la_1" => File.read('/proc/loadavg').split(/\s+/)[2].to_f
6
- }
4
+ { :service => plugin.service + "la_1", :metric => File.read('/proc/loadavg').split(/\s+/)[2].to_f }
7
5
  end
8
6
 
9
7
  end
@@ -1,6 +1,6 @@
1
1
  class Riemann::Babbler::Memory < Riemann::Babbler
2
2
 
3
- def memory
3
+ def collect
4
4
  m = File.read('/proc/meminfo').split(/\n/).inject({}) { |info, line|
5
5
  x = line.split(/:?\s+/)
6
6
  info[x[0]] = x[1].to_i
@@ -9,27 +9,12 @@ class Riemann::Babbler::Memory < Riemann::Babbler
9
9
  free = m['MemFree'].to_i + m['Buffers'].to_i + m['Cached'].to_i
10
10
  total = m['MemTotal'].to_i
11
11
  fraction = 1 - (free.to_f / total)
12
- return {:free => (free.to_f/1024), :fraction => fraction, :total => (total.to_f/1024)}
13
- end
14
12
 
15
- def tick
16
- current_state = memory
17
- # соотношение свободной/занятой
18
- report({
19
- :service => plugin.service,
20
- :state => state(current_state[:fraction]),
21
- :metric => current_state[:fraction]
22
- })
23
- # постим сообщение о свобоной памяти
24
- report({
25
- :service => plugin.service + " free",
26
- :metric => current_state[:free]
27
- }) if plugin.report_free
28
- # постим сообение о том сколько у нас вообще памяти
29
- report({
30
- :service => plugin.service + " total",
31
- :metric => current_state[:total]
32
- }) if plugin.report_total
13
+ [
14
+ { :service => plugin.service, :metric => fraction },
15
+ { :service => plugin.service + " free", :metric => free.to_f },
16
+ { :service => plugin.service + " total", :metric => total.to_f}
17
+ ]
33
18
  end
34
19
 
35
20
  end
@@ -16,17 +16,9 @@ class Riemann::Babbler::Net < Riemann::Babbler
16
16
  'tx carrier',
17
17
  'tx compressed']
18
18
 
19
- def plugin
20
- options.plugins.net
21
- end
22
-
23
- def init
24
- @old_status = Hash.new
25
- end
26
-
27
- def net
19
+ def collect
28
20
  f = File.read('/proc/net/dev')
29
- status = Hash.new
21
+ status = Array.new
30
22
  f.split("\n").each do |line|
31
23
  iface = line.split(":")[0].strip
32
24
  iface.gsub!(/\./,"_")
@@ -36,22 +28,10 @@ class Riemann::Babbler::Net < Riemann::Babbler
36
28
  end.zip(
37
29
  $2.split(/\s+/).map { |str| str.to_i }
38
30
  ).each do |service, value|
39
- status.merge!({service => value})
31
+ status << { :service => service, :metric => value, :is_diff => true }
40
32
  end
41
33
  end
42
34
  status
43
35
  end
44
36
 
45
- def tick
46
- status = net
47
- status.each_key do |service|
48
- #next if status[service] == 0
49
- report({
50
- :service => service,
51
- :metric => status[service],
52
- :is_diff => true
53
- })
54
- end
55
- end
56
-
57
37
  end
@@ -1,5 +1,5 @@
1
1
  module Riemann
2
2
  class Babbler
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-babbler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: 1972461691726905926
150
+ hash: -3405522857868572871
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements: