Skip to content

Commit

Permalink
15267 - support surpressing aggregate summaries in printrpcstats
Browse files Browse the repository at this point in the history
The aggregate summary stats is always available and always printed but
we really dont know what users want in their custom applications, it
seems that often they wont want summaries printed like in the case of
'fact' application.

So this changes the default that the summaries are not printed always
from the printrpcstats call but only when :summarize => true is passed
this should provide maximum backward compatability
  • Loading branch information
ripienaar committed Jun 28, 2012
1 parent b918bb8 commit f6801bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/mcollective/rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ def self.discovered(discovered)
# If you've passed -v on the command line a detailed stat block
# will be printed, else just a one liner.
#
# You can pass flags into it, at the moment only one flag is
# supported:
# You can pass flags into it:
#
# printrpcstats :caption => "Foo"
# printrpcstats :caption => "Foo", :summarize => true
#
# This will use "Foo" as the caption to the stats in verbose
# mode
# mode and print out any aggregate summary information if present
def printrpcstats(flags={})
return unless @options[:output_format] == :console

flags = {:summarize => false, :caption => "rpc stats"}.merge(flags)

verbose = @options[:verbose] rescue verbose = false
caption = flags[:caption] || "rpc stats"

begin
stats = @@stats
Expand All @@ -134,7 +134,7 @@ def printrpcstats(flags={})
return
end

puts stats.report(caption, verbose)
puts stats.report(flags[:caption], flags[:summarize], verbose)
end

# Prints the result of an RPC call.
Expand Down
15 changes: 12 additions & 3 deletions lib/mcollective/rpc/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ def text_for_aggregates

# Returns a blob of text representing the request status based on the
# stats contained in this class
def report(caption = "rpc stats", verbose = false)
def report(caption = "rpc stats", summarize = true, verbose = false)
result_text = []

if verbose
result_text << text_for_aggregates if @aggregate_summary
if @aggregate_summary && summarize
result_text << text_for_aggregates
else
result_text << ""
end

result_text << Util.colorize(:yellow, "---- #{caption} ----")

Expand All @@ -179,7 +183,12 @@ def report(caption = "rpc stats", verbose = false)
if @discovered
@responses < @discovered ? color = :red : color = :green

result_text << text_for_aggregates if @aggregate_summary
if @aggregate_summary && summarize
result_text << text_for_aggregates
else
result_text << ""
end

result_text << "Finished processing %s / %s hosts in %.2f ms" % [Util.colorize(color, @responses), Util.colorize(color, @discovered), @blocktime * 1000]
else
result_text << "Finished processing %s hosts in %.2f ms" % [Util.colorize(:bold, @responses), @blocktime * 1000]
Expand Down
2 changes: 1 addition & 1 deletion plugins/mcollective/application/rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def main

printrpc mc.send(configuration[:action], configuration[:arguments])

printrpcstats :caption => "#{configuration[:agent]}##{configuration[:action]} call stats" if mc.discover.size > 0
printrpcstats :summarize => true, :caption => "#{configuration[:agent]}##{configuration[:action]} call stats" if mc.discover.size > 0

halt mc.stats
end
Expand Down

0 comments on commit f6801bd

Please sign in to comment.