ruminate 0.0.2 → 0.0.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.
data/History.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Ruminate Changelog
2
2
  =====================
3
3
 
4
+ 0.0.3
5
+
6
+ - Beginning template stuff.
7
+
8
+ 0.0.2
9
+
10
+ - Bug fix for removing links after capistrano deploys.
11
+
4
12
  0.0.1
5
13
 
6
14
  - Initial release
data/README.md CHANGED
@@ -96,7 +96,7 @@ When you deploy, perform the following:
96
96
 
97
97
  ## TODO
98
98
 
99
- Too much repitition. Create templates for plot stuff in timers, etc.
99
+ Use deep_merge for better templating?
100
100
 
101
101
  Make sure the example above actually works.
102
102
 
@@ -0,0 +1,16 @@
1
+ :requires: measurement
2
+ :graph_args: --base 1000 -l 0
3
+ :graph_vlabel: msec
4
+ :plot:
5
+ - :label: avg
6
+ :info: Average time of %measurement%
7
+ :draw: LINE
8
+ :field: avg_time
9
+ - :label: min
10
+ :info: Min time of %measurement%
11
+ :draw: LINE
12
+ :field: min_time
13
+ - :label: max
14
+ :info: Max time of %measurement%
15
+ :draw: LINE
16
+ :field: max_time
@@ -40,8 +40,11 @@ def ruminate(arg0, rumx_mount, username, password, host, port, smtp_host, config
40
40
  res.body.split("\n").each do |line|
41
41
  if (i = line.index('=')) >= 0
42
42
  value = line[(i+1)..-1]
43
- # TODO: Necessary to do an integer check?
44
- value = value.to_f if value.match(/^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/)
43
+ if value.match(/^\s*[+-]?\d+\s*$/)
44
+ value = value.to_i
45
+ elsif value.match(/^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/)
46
+ value = value.to_f
47
+ end
45
48
  result_hash[line[0,i]] = value
46
49
  end
47
50
  end
@@ -64,6 +67,9 @@ def ruminate(arg0, rumx_mount, username, password, host, port, smtp_host, config
64
67
  The following filter has been triggered:
65
68
 
66
69
  #{filter}
70
+
71
+ Output:
72
+ #{res.body}
67
73
  EOM
68
74
  send_email(smtp_host, alert[:email], "ALERT: #{alert[:title]}", message)
69
75
  end
@@ -73,8 +79,12 @@ The following filter caused an exception #{e.message}:
73
79
 
74
80
  Original Filter: #{alert[:filter]}
75
81
  Evaled Filter: #{filter}
82
+
83
+ Output:
84
+ #{res.body}
76
85
  EOM
77
86
  send_email(smtp_host, alert[:email], "ALERT EXCEPTION: #{alert[:title]}", message)
87
+ raise
78
88
  end
79
89
  end
80
90
  end
data/lib/ruminate.rb CHANGED
@@ -5,7 +5,6 @@ module Ruminate
5
5
  require 'ruminate/railtie' if defined?(Rails)
6
6
 
7
7
  def self.create_plugins(config_file, ruminate_dir, plugin_dir)
8
- FileUtils.rm_rf(plugin_dir)
9
8
  FileUtils.mkdir_p(plugin_dir)
10
9
  config = YAML.load(File.read(config_file))
11
10
  ruminate_plugin = File.expand_path('../ruminate/plugin.rb', __FILE__)
@@ -20,8 +19,10 @@ module Ruminate
20
19
  Dir["#{ruminate_dir}/*.yml"].each do |plugin_config_file|
21
20
  plugin_basename = File.basename(plugin_config_file, '.*')
22
21
  plugin_config = YAML.load(File.read(plugin_config_file))
22
+ replace_templates(plugin_config, ruminate_dir)
23
23
  plugin_config.each do |graph_category, graph_configs|
24
24
  graph_configs.each do |graph_config|
25
+ raise "No plot\n#{graph_config.inspect}" unless graph_config[:plot]
25
26
  config_params = ''
26
27
  graph_config.each do |key, value|
27
28
  config_params += "#{key} #{value}\n" if key.to_s.start_with?('graph_')
@@ -29,6 +30,7 @@ module Ruminate
29
30
  config_params += "graph_category #{graph_category}\n" unless graph_config[:graph_category]
30
31
  graph_config[:plot].each_with_index do |field_hash, i|
31
32
  field_hash.each do |key, value|
33
+ next if key == :field
32
34
  config_params += "field#{i}.#{key} #{value}\n"
33
35
  end
34
36
  end
@@ -87,4 +89,59 @@ ruminate(
87
89
  end
88
90
  #system '/etc/init.d/munin-node restart'
89
91
  end
92
+
93
+ private
94
+
95
+ def self.replace_templates(hash, ruminate_dir)
96
+ read_hash = hash.dup
97
+ read_hash.each do |key, value|
98
+ if key == :template
99
+ hash.delete(:template)
100
+ add_template_to_hash(hash, ruminate_dir, value)
101
+ else
102
+ replace_value(value, ruminate_dir)
103
+ end
104
+ end
105
+ end
106
+
107
+ def self.add_template_to_hash(hash, ruminate_dir, template_value)
108
+ variables = template_value.split
109
+ template_name = variables.shift
110
+ filename = File.join(ruminate_dir, 'templates', "#{template_name}.yml")
111
+ unless File.exist?(filename)
112
+ filename = File.expand_path("../../config/templates/#{template_name}.yml", __FILE__)
113
+ raise "Could not find template #{template_name}.yml" unless File.exist?(filename)
114
+ end
115
+ child_hash = YAML.load(File.read(filename))
116
+ raise "Template #{template_name}.yml is not a hash" unless child_hash.kind_of?(Hash)
117
+ variable_hash = {}
118
+ variables.each do |value|
119
+ eq_i = value.index('=')
120
+ raise "Invalid substitution value #{value}" unless eq_i
121
+ variable_hash[value[0,eq_i]] = value[eq_i+1..-1]
122
+ end
123
+ replace_variables(child_hash, variable_hash)
124
+ replace_templates(child_hash, ruminate_dir)
125
+ hash.merge!(child_hash)
126
+ end
127
+
128
+ def self.replace_value(value, ruminate_dir)
129
+ if value.kind_of?(Array)
130
+ value.each {|sub_value| replace_value(sub_value, ruminate_dir)}
131
+ elsif value.kind_of?(Hash)
132
+ replace_templates(value, ruminate_dir)
133
+ end
134
+ end
135
+
136
+ def self.replace_variables(value, variable_hash)
137
+ if value.kind_of?(String)
138
+ variable_hash.each do |variable, sub|
139
+ value.gsub!("%#{variable}%", sub)
140
+ end
141
+ elsif value.kind_of?(Array)
142
+ value.each {|sub_value| replace_variables(sub_value, variable_hash)}
143
+ elsif value.kind_of?(Hash)
144
+ value.each_value {|sub_value| replace_variables(sub_value, variable_hash)}
145
+ end
146
+ end
90
147
  end
metadata CHANGED
@@ -1,64 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruminate
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.3
6
6
  platform: ruby
7
- authors:
8
- - Brad Pardee
7
+ authors:
8
+ - Brad Pardee
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-05 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rumx
16
- requirement: &70280445823820 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 0.1.1
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *70280445823820
12
+
13
+ date: 2012-01-11 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rumx
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.5
24
+ type: :runtime
25
+ version_requirements: *id001
25
26
  description: Simple process for generating munin plugins to monitor your Rails application
26
- email:
27
- - bradpardee@gmail.com
27
+ email:
28
+ - bradpardee@gmail.com
28
29
  executables: []
30
+
29
31
  extensions: []
32
+
30
33
  extra_rdoc_files: []
31
- files:
32
- - lib/ruminate/plugin.rb
33
- - lib/ruminate/railtie.rb
34
- - lib/ruminate.rb
35
- - lib/tasks/ruminate.rake
36
- - LICENSE.txt
37
- - Rakefile
38
- - History.md
39
- - README.md
34
+
35
+ files:
36
+ - lib/ruminate.rb
37
+ - lib/ruminate/plugin.rb
38
+ - lib/ruminate/railtie.rb
39
+ - lib/tasks/ruminate.rake
40
+ - config/templates/plot_timer.yml
41
+ - LICENSE.txt
42
+ - Rakefile
43
+ - History.md
44
+ - README.md
40
45
  homepage: http://github.com/ClarityServices/ruminate
41
46
  licenses: []
47
+
42
48
  post_install_message:
43
49
  rdoc_options: []
44
- require_paths:
45
- - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
47
54
  none: false
48
- requirements:
49
- - - ! '>='
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
60
  none: false
54
- requirements:
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: '0'
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
58
65
  requirements: []
66
+
59
67
  rubyforge_project:
60
- rubygems_version: 1.8.10
68
+ rubygems_version: 1.8.9
61
69
  signing_key:
62
70
  specification_version: 3
63
71
  summary: Easy generation of munin plugins to monitor your app
64
72
  test_files: []
73
+