Class Puppet::Transaction::Report
In: lib/puppet/transaction/report.rb
Parent: Object

A class for reporting what happens on each client. Reports consist of two types of data: Logs and Metrics. Logs are the output that each change produces, and Metrics are all of the numerical data involved in the transaction.

Methods

<<   name   new   newlog   newmetric   record   summary  

Attributes

host  [RW] 
logs  [RW] 
metrics  [RW] 
time  [RW] 

Public Class methods

[Source]

    # File lib/puppet/transaction/report.rb, line 20
20:     def initialize
21:         @metrics = {}
22:         @logs = []
23: 
24:         @records = Hash.new do |hash, key|
25:             hash[key] = []
26:         end
27: 
28:         @host = Puppet[:certname]
29:     end

Public Instance methods

[Source]

    # File lib/puppet/transaction/report.rb, line 15
15:     def <<(msg)
16:         @logs << msg
17:         return self
18:     end

[Source]

    # File lib/puppet/transaction/report.rb, line 31
31:     def name
32:         host
33:     end

Add a new log message.

[Source]

    # File lib/puppet/transaction/report.rb, line 47
47:     def newlog(msg)
48:         @logs << msg
49:     end

Create a new metric.

[Source]

    # File lib/puppet/transaction/report.rb, line 36
36:     def newmetric(name, hash)
37:         metric = Puppet::Util::Metric.new(name)
38: 
39:         hash.each do |name, value|
40:             metric.newvalue(name, value)
41:         end
42: 
43:         @metrics[metric.name] = metric
44:     end

[Source]

    # File lib/puppet/transaction/report.rb, line 51
51:     def record(metric, object)
52:         @records[metric] << object
53:     end

Provide a summary of this report.

[Source]

    # File lib/puppet/transaction/report.rb, line 56
56:     def summary
57:         ret = ""
58: 
59:         @metrics.sort { |a,b| a[1].label <=> b[1].label }.each do |name, metric|
60:             ret += "%s:\n" % metric.label
61:             metric.values.sort { |a,b|
62:                 # sort by label
63:                 if a[0] == :total
64:                     1
65:                 elsif b[0] == :total
66:                     -1
67:                 else
68:                     a[1] <=> b[1]
69:                 end
70:             }.each do |name, label, value|
71:                 next if value == 0
72:                 if value.is_a?(Float)
73:                     value = "%0.2f" % value
74:                 end
75:                 ret += "   %15s %s\n" % [label + ":", value]
76:             end
77:         end
78:         return ret
79:     end

[Validate]