diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-04 05:04:29 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-04 05:04:29 +0000 |
commit | 28254b55cc65d572e9036046d7765c6dd7505e70 (patch) | |
tree | 5ae1067534c9bdf6de73a79836afb3ba84438d36 /lib | |
parent | 0c07125397428a0c1ca9a4a4d0176f45d8be0979 (diff) | |
download | puppet-28254b55cc65d572e9036046d7765c6dd7505e70.tar.gz puppet-28254b55cc65d572e9036046d7765c6dd7505e70.tar.xz puppet-28254b55cc65d572e9036046d7765c6dd7505e70.zip |
Adding a --summarize option, to get a transaction summary
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2459 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/network/client/master.rb | 25 | ||||
-rw-r--r-- | lib/puppet/reports/rrdgraph.rb | 13 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 15 | ||||
-rw-r--r-- | lib/puppet/transaction/report.rb | 26 |
4 files changed, 62 insertions, 17 deletions
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index b967729b5..9c1aed8ee 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -74,7 +74,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client Puppet::Util::Storage.store end - if Puppet[:report] + if Puppet[:report] or Puppet[:summarize] report(transaction) end @@ -501,12 +501,25 @@ class Puppet::Network::Client::Master < Puppet::Network::Client def report(transaction) begin report = transaction.generate_report() - if Puppet[:rrdgraph] == true - report.graph() - end - reportclient().report(report) rescue => detail - Puppet.err "Reporting failed: %s" % detail + Puppet.err "Could not generate report: %s" % detail + return + end + + if Puppet[:rrdgraph] == true + report.graph() + end + + if Puppet[:summarize] + puts report.summary + end + + if Puppet[:report] + begin + reportclient().report(report) + rescue => detail + Puppet.err "Reporting failed: %s" % detail + end end end diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb index 49ab7452b..005efdca8 100644 --- a/lib/puppet/reports/rrdgraph.rb +++ b/lib/puppet/reports/rrdgraph.rb @@ -110,6 +110,11 @@ Puppet::Network::Handler.report.newreport(:rrdgraph) do self.metrics.each do |name, metric| metric.basedir = hostdir + + if name == :time + timeclean(metric) + end + metric.store(time) metric.graph @@ -119,6 +124,14 @@ Puppet::Network::Handler.report.newreport(:rrdgraph) do mkhtml() end end + + # Unfortunately, RRD does not deal well with changing lists of values, + # so we have to pick a list of values and stick with it. In this case, + # that means we record the total time, the config time, and that's about + # it. We should probably send each type's time as a separate metric. + def timeclean(metric) + metric.values = metric.values.find_all { |name, label, value| name == :total } + end end # $Id$ diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index e211b0f5b..9eaca63a6 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -27,7 +27,10 @@ class Transaction Values must be comma-separated."], :evaltrace => [false, "Whether each resource should log when it is being evaluated. This allows you to interactively see exactly - what is being done."] + what is being done."], + :summarize => [false, + "Whether to print a transaction summary." + ] ) # Add some additional times for reporting @@ -409,16 +412,6 @@ class Transaction total end - # Unfortunately, RRD does not deal well with changing lists of values, - # so we have to pick a list of values and stick with it. In this case, - # that means we record the total time, the config time, and that's about - # it. We should probably send each type's time as a separate metric. - @timemetrics.dup.each do |name, value| - if Puppet::Type.type(name) - @timemetrics.delete(name) - end - end - # Add all of the metrics related to resource count and status @report.newmetric(:resources, @resourcemetrics) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index ad6b82a8a..095b6c810 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -48,6 +48,32 @@ class Puppet::Transaction::Report def record(metric, object) @records[metric] << object end + + # Provide a summary of this report. + def summary + ret = "" + + @metrics.sort { |a,b| a[1].label <=> b[1].label }.each do |name, metric| + ret += "%s:\n" % metric.label + metric.values.sort { |a,b| + # sort by label + if a[0] == :total + 1 + elsif b[0] == :total + -1 + else + a[1] <=> b[1] + end + }.each do |name, label, value| + next if value == 0 + if value.is_a?(Float) + value = "%0.2f" % value + end + ret += " %15s %s\n" % [label + ":", value] + end + end + return ret + end end # $Id$ |