Class: GraphiteReporting
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- GraphiteReporting
- Defined in:
- lib/chef-handler-graphite.rb
Instance Attribute Summary collapse
-
#graphite_host ⇒ Object
writeonly
Sets the attribute graphite_host.
-
#graphite_port ⇒ Object
writeonly
Sets the attribute graphite_port.
-
#metric_key ⇒ Object
writeonly
Sets the attribute metric_key.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GraphiteReporting
constructor
A new instance of GraphiteReporting.
- #report ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GraphiteReporting
Returns a new instance of GraphiteReporting.
28 29 30 31 32 |
# File 'lib/chef-handler-graphite.rb', line 28 def initialize( = {}) @metric_key = [:metric_key] @graphite_host = [:graphite_host] @graphite_port = [:graphite_port] end |
Instance Attribute Details
#graphite_host=(value) ⇒ Object (writeonly)
Sets the attribute graphite_host
26 27 28 |
# File 'lib/chef-handler-graphite.rb', line 26 def graphite_host=(value) @graphite_host = value end |
#graphite_port=(value) ⇒ Object (writeonly)
Sets the attribute graphite_port
26 27 28 |
# File 'lib/chef-handler-graphite.rb', line 26 def graphite_port=(value) @graphite_port = value end |
#metric_key=(value) ⇒ Object (writeonly)
Sets the attribute metric_key
26 27 28 |
# File 'lib/chef-handler-graphite.rb', line 26 def metric_key=(value) @metric_key = value end |
Instance Method Details
#report ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef-handler-graphite.rb', line 34 def report gemspec = if Gem::Specification.respond_to? :find_by_name Gem::Specification.find_by_name('chef-handler-graphite') else Gem.source_index.find_name('chef-handler-graphite').last end Chef::Log.debug("#{gemspec.full_name} loaded as a handler.") g = Graphite.new g.host = @graphite_host g.port = @graphite_port metrics = Hash.new metrics[:updated_resources] = run_status.updated_resources.length if run_status.updated_resources metrics[:all_resources] = run_status.all_resources.length if run_status.all_resources metrics[:elapsed_time] = run_status.elapsed_time if run_status.success? metrics[:success] = 1 metrics[:fail] = 0 else metrics[:success] = 0 metrics[:fail] = 1 end g.push_to_graphite do |graphite| metrics.each do |metric, value| Chef::Log.debug("#{@metric_key}.#{metric} #{value} #{g.time_now}") graphite.puts "#{@metric_key}.#{metric} #{value} #{g.time_now}" end end end |