Class | MCollective::RPC::Stats |
In: |
lib/mcollective/rpc/stats.rb
|
Parent: | Object |
Class to wrap all the stats and to keep track of some timings
aggregate_summary | [RW] | |
blocktime | [RW] | |
ddl | [RW] | |
discovered | [RW] | |
discovered_nodes | [RW] | |
discoverytime | [RW] | |
failcount | [RW] | |
noresponsefrom | [RW] | |
noresponsefrom | [RW] | |
okcount | [RW] | |
requestid | [RW] | |
responses | [RW] | |
responsesfrom | [RW] | |
starttime | [RW] | |
totaltime | [RW] |
Fake hash access to keep things backward compatible
# File lib/mcollective/rpc/stats.rb, line 49 49: def [](key) 50: to_hash[key] 51: rescue 52: nil 53: end
Re-initializes the object with stats from the basic client
# File lib/mcollective/rpc/stats.rb, line 70 70: def client_stats=(stats) 71: @noresponsefrom = stats[:noresponsefrom] 72: @responses = stats[:responses] 73: @starttime = stats[:starttime] 74: @blocktime = stats[:blocktime] 75: @totaltime = stats[:totaltime] 76: @requestid = stats[:requestid] 77: @discoverytime = stats[:discoverytime] if @discoverytime == 0 78: end
Update discovered and discovered_nodes based on discovery results
# File lib/mcollective/rpc/stats.rb, line 108 108: def discovered_agents(agents) 109: @discovered_nodes = agents 110: @discovered = agents.size 111: end
increment the count of failed hosts
# File lib/mcollective/rpc/stats.rb, line 63 63: def fail 64: @failcount += 1 65: rescue 66: @failcount = 1 67: end
Helper to calculate total time etc
# File lib/mcollective/rpc/stats.rb, line 114 114: def finish_request 115: @totaltime = @blocktime + @discoverytime 116: 117: # figures out who we had no responses from 118: dhosts = @discovered_nodes.clone 119: @responsesfrom.each {|r| dhosts.delete(r)} 120: @noresponsefrom = dhosts 121: rescue 122: @totaltime = 0 123: @noresponsefrom = [] 124: end
Returns a blob of text indicating what nodes did not respond
# File lib/mcollective/rpc/stats.rb, line 213 213: def no_response_report 214: result_text = StringIO.new 215: 216: if @noresponsefrom.size > 0 217: result_text.puts 218: result_text.puts Util.colorize(:red, "No response from:") 219: result_text.puts 220: 221: @noresponsefrom.sort.in_groups_of(3) do |c| 222: result_text.puts " %-30s%-30s%-30s" % c 223: end 224: 225: result_text.puts 226: end 227: 228: result_text.string 229: end
Helper to keep track of who we received responses from
# File lib/mcollective/rpc/stats.rb, line 127 127: def node_responded(node) 128: @responsesfrom << node 129: rescue 130: @responsesfrom = [node] 131: end
Returns a blob of text representing the request status based on the stats contained in this class
# File lib/mcollective/rpc/stats.rb, line 163 163: def report(caption = "rpc stats", summarize = true, verbose = false) 164: result_text = [] 165: 166: if verbose 167: if @aggregate_summary.size > 0 && summarize 168: result_text << text_for_aggregates 169: else 170: result_text << "" 171: end 172: 173: result_text << Util.colorize(:yellow, "---- #{caption} ----") 174: 175: if @discovered 176: @responses < @discovered ? color = :red : color = :reset 177: result_text << " Nodes: %s / %s" % [ Util.colorize(color, @discovered), Util.colorize(color, @responses) ] 178: else 179: result_text << " Nodes: #{@responses}" 180: end 181: 182: @failcount < 0 ? color = :red : color = :reset 183: 184: result_text << " Pass / Fail: %s / %s" % [Util.colorize(color, @okcount), Util.colorize(color, @failcount) ] 185: result_text << " Start Time: %s" % [Time.at(@starttime)] 186: result_text << " Discovery Time: %.2fms" % [@discoverytime * 1000] 187: result_text << " Agent Time: %.2fms" % [@blocktime * 1000] 188: result_text << " Total Time: %.2fms" % [@totaltime * 1000] 189: else 190: if @discovered 191: @responses < @discovered ? color = :red : color = :green 192: 193: if @aggregate_summary.size > 0 && summarize 194: result_text << text_for_aggregates 195: else 196: result_text << "" 197: end 198: 199: result_text << "Finished processing %s / %s hosts in %.2f ms" % [Util.colorize(color, @responses), Util.colorize(color, @discovered), @blocktime * 1000] 200: else 201: result_text << "Finished processing %s hosts in %.2f ms" % [Util.colorize(:bold, @responses), @blocktime * 1000] 202: end 203: end 204: 205: if no_response_report != "" 206: result_text << "" << no_response_report 207: end 208: 209: result_text.join("\n") 210: end
Resets stats, if discovery time is set we keep it as it was
# File lib/mcollective/rpc/stats.rb, line 14 14: def reset 15: @noresponsefrom = [] 16: @responsesfrom = [] 17: @responses = 0 18: @starttime = Time.now.to_f 19: @discoverytime = 0 unless @discoverytime 20: @blocktime = 0 21: @totaltime = 0 22: @discovered = 0 23: @discovered_nodes = [] 24: @okcount = 0 25: @failcount = 0 26: @noresponsefrom = [] 27: @requestid = nil 28: @aggregate_summary = [] 29: end
# File lib/mcollective/rpc/stats.rb, line 133 133: def text_for_aggregates 134: result = StringIO.new 135: 136: @aggregate_summary.each do |aggregate| 137: output_item = aggregate.result[:output] 138: 139: begin 140: action_interface = @ddl.action_interface(aggregate.action) 141: display_as = action_interface[:output][output_item][:display_as] 142: rescue 143: display_as = output_item 144: end 145: 146: aggregate_report = aggregate.to_s 147: 148: result.puts Util.colorize(:bold, "Summary of %s:" % display_as) 149: result.puts 150: unless aggregate_report == "" 151: result.puts aggregate.to_s 152: else 153: result.puts Util.colorize(:yellow, " No aggregate summary could be computed") 154: end 155: result.puts 156: end 157: 158: result.string 159: end
helper to time block execution time
# File lib/mcollective/rpc/stats.rb, line 94 94: def time_block_execution(action) 95: if action == :start 96: @block_start = Time.now.to_f 97: elsif action == :end 98: @blocktime += Time.now.to_f - @block_start 99: else 100: raise("Uknown block action #{action}") 101: end 102: rescue 103: @blocktime = 0 104: end
Utility to time discovery from :start to :end
# File lib/mcollective/rpc/stats.rb, line 81 81: def time_discovery(action) 82: if action == :start 83: @discovery_start = Time.now.to_f 84: elsif action == :end 85: @discoverytime = Time.now.to_f - @discovery_start 86: else 87: raise("Uknown discovery action #{action}") 88: end 89: rescue 90: @discoverytime = 0 91: end
returns a hash of our stats
# File lib/mcollective/rpc/stats.rb, line 32 32: def to_hash 33: {:noresponsefrom => @noresponsefrom, 34: :starttime => @starttime, 35: :discoverytime => @discoverytime, 36: :blocktime => @blocktime, 37: :responses => @responses, 38: :totaltime => @totaltime, 39: :discovered => @discovered, 40: :discovered_nodes => @discovered_nodes, 41: :noresponsefrom => @noresponsefrom, 42: :okcount => @okcount, 43: :requestid => @requestid, 44: :failcount => @failcount, 45: :aggregate_summary => @aggregate_summary} 46: end