Class: Puppet::Transaction::Report
- Extended by:
- Indirector
- Defined in:
- lib/puppet/transaction/report.rb
Overview
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.
Defined Under Namespace
Classes: Processor, Rest, Yaml
Instance Attribute Summary collapse
-
#configuration_version ⇒ Object
Returns the value of attribute configuration_version.
-
#host ⇒ Object
Returns the value of attribute host.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#resource_statuses ⇒ Object
readonly
Returns the value of attribute resource_statuses.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
-
.default_format ⇒ Object
This is necessary since Marshall doesn’t know how to dump hash with default proc (see below @records).
Instance Method Summary collapse
- #<<(msg) ⇒ Object
- #add_metric(name, hash) ⇒ Object
- #add_resource_status(status) ⇒ Object
- #add_times(name, value) ⇒ Object
- #compute_status(resource_metrics, change_metric) ⇒ Object
-
#exit_status ⇒ Object
Based on the contents of this report’s metrics, compute a single number that represents the report.
- #finalize_report ⇒ Object
-
#initialize(kind, configuration_version = nil) ⇒ Report
constructor
A new instance of Report.
- #name ⇒ Object
-
#raw_summary ⇒ Object
Provide a raw hash summary of this report.
-
#summary ⇒ Object
Provide a human readable textual summary of this report.
- #to_yaml_properties ⇒ Object
Methods included from Indirector
Constructor Details
#initialize(kind, configuration_version = nil) ⇒ Report
Returns a new instance of Report.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/transaction/report.rb', line 65 def initialize(kind, configuration_version=nil) @metrics = {} @logs = [] @resource_statuses = {} @external_times ||= {} @host = Puppet[:node_name_value] @time = Time.now @kind = kind @report_format = 2 @puppet_version = Puppet.version @configuration_version = configuration_version @status = 'failed' # assume failed until the report is finalized end |
Instance Attribute Details
#configuration_version ⇒ Object
Returns the value of attribute configuration_version.
13 14 15 |
# File 'lib/puppet/transaction/report.rb', line 13 def configuration_version @configuration_version end |
#host ⇒ Object
Returns the value of attribute host.
13 14 15 |
# File 'lib/puppet/transaction/report.rb', line 13 def host @host end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def kind @kind end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def logs @logs end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def metrics @metrics end |
#resource_statuses ⇒ Object (readonly)
Returns the value of attribute resource_statuses.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def resource_statuses @resource_statuses end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def status @status end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
14 15 16 |
# File 'lib/puppet/transaction/report.rb', line 14 def time @time end |
Class Method Details
.default_format ⇒ Object
This is necessary since Marshall doesn’t know how to dump hash with default proc (see below @records)
18 19 20 |
# File 'lib/puppet/transaction/report.rb', line 18 def self.default_format :yaml end |
Instance Method Details
#<<(msg) ⇒ Object
22 23 24 25 |
# File 'lib/puppet/transaction/report.rb', line 22 def <<(msg) @logs << msg self end |
#add_metric(name, hash) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet/transaction/report.rb', line 31 def add_metric(name, hash) metric = Puppet::Util::Metric.new(name) hash.each do |name, value| metric.newvalue(name, value) end @metrics[metric.name] = metric metric end |
#add_resource_status(status) ⇒ Object
42 43 44 |
# File 'lib/puppet/transaction/report.rb', line 42 def add_resource_status(status) @resource_statuses[status.resource] = status end |
#add_times(name, value) ⇒ Object
27 28 29 |
# File 'lib/puppet/transaction/report.rb', line 27 def add_times(name, value) @external_times[name] = value end |
#compute_status(resource_metrics, change_metric) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/puppet/transaction/report.rb', line 46 def compute_status(resource_metrics, change_metric) if (resource_metrics["failed"] || 0) > 0 'failed' elsif change_metric > 0 'changed' else 'unchanged' end end |
#exit_status ⇒ Object
Based on the contents of this report’s metrics, compute a single number that represents the report. The resulting number is a bitmask where individual bits represent the presence of different metrics.
129 130 131 132 133 134 |
# File 'lib/puppet/transaction/report.rb', line 129 def exit_status status = 0 status |= 2 if @metrics["changes"]["total"] > 0 status |= 4 if @metrics["resources"]["failed"] > 0 status end |
#finalize_report ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/puppet/transaction/report.rb', line 56 def finalize_report resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) change_metric = calculate_change_metric add_metric(:changes, {"total" => change_metric}) add_metric(:events, calculate_event_metrics) @status = compute_status(resource_metrics, change_metric) end |
#name ⇒ Object
79 80 81 |
# File 'lib/puppet/transaction/report.rb', line 79 def name host end |
#raw_summary ⇒ Object
Provide a raw hash summary of this report.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/puppet/transaction/report.rb', line 111 def raw_summary report = {} @metrics.each do |name, metric| key = metric.name.to_s report[key] = {} metric.values.each do |name, label, value| report[key][name.to_s] = value end report[key]["total"] = 0 unless key == "time" or report[key].include?("total") end (report["time"] ||= {})["last_run"] = Time.now.tv_sec report end |
#summary ⇒ Object
Provide a human readable textual summary of this report.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppet/transaction/report.rb', line 84 def summary report = raw_summary ret = "" report.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key| ret += "#{Puppet::Util::Metric.labelize(key)}:\n" report[key].keys.sort { |a,b| # sort by label if a == :total 1 elsif b == :total -1 else report[key][a].to_s <=> report[key][b].to_s end }.each do |label| value = report[key][label] next if value == 0 value = "%0.2f" % value if value.is_a?(Float) ret += " %15s %s\n" % [Puppet::Util::Metric.labelize(label) + ":", value] end end ret end |
#to_yaml_properties ⇒ Object
136 137 138 |
# File 'lib/puppet/transaction/report.rb', line 136 def to_yaml_properties (instance_variables - ["@external_times"]).sort end |