| 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
| blocktime | [RW] | |
| discovered | [RW] | |
| discovered_nodes | [RW] | |
| discoverytime | [RW] | |
| failcount | [RW] | |
| noresponsefrom | [RW] | |
| noresponsefrom | [RW] | |
| okcount | [RW] | |
| responses | [RW] | |
| responsesfrom | [RW] | |
| starttime | [RW] | |
| totaltime | [RW] |
Fake hash access to keep things backward compatible
# File lib/mcollective/rpc/stats.rb, line 44
44: def [](key)
45: to_hash[key]
46: rescue
47: nil
48: end
Re-initializes the object with stats from the basic client
# File lib/mcollective/rpc/stats.rb, line 65
65: def client_stats=(stats)
66: @noresponsefrom = stats[:noresponsefrom]
67: @responses = stats[:responses]
68: @starttime = stats[:starttime]
69: @blocktime = stats[:blocktime]
70: @totaltime = stats[:totaltime]
71: @discoverytime = stats[:discoverytime] if @discoverytime == 0
72: end
Update discovered and discovered_nodes based on discovery results
# File lib/mcollective/rpc/stats.rb, line 102
102: def discovered_agents(agents)
103: @discovered_nodes = agents
104: @discovered = agents.size
105: end
increment the count of failed hosts
# File lib/mcollective/rpc/stats.rb, line 58
58: def fail
59: @failcount += 1
60: rescue
61: @failcount = 1
62: end
Helper to calculate total time etc
# File lib/mcollective/rpc/stats.rb, line 108
108: def finish_request
109: @totaltime = @blocktime + @discoverytime
110:
111: # figures out who we had no responses from
112: dhosts = @discovered_nodes.clone
113: @responsesfrom.each {|r| dhosts.delete(r)}
114: @noresponsefrom = dhosts
115: rescue
116: @totaltime = 0
117: @noresponsefrom = []
118: end
Returns a blob of text indicating what nodes did not respond
# File lib/mcollective/rpc/stats.rb, line 167
167: def no_response_report
168: result_text = []
169:
170: if @noresponsefrom.size > 0
171: result_text << Helpers.colorize(:red, "\nNo response from:\n")
172:
173: @noresponsefrom.each_with_index do |c,i|
174: result_text << "" if i % 4 == 0
175: result_text << "%30s" % [c]
176: end
177:
178: result_text << ""
179: end
180:
181: result_text.join("\n")
182: end
Helper to keep track of who we received responses from
# File lib/mcollective/rpc/stats.rb, line 121
121: def node_responded(node)
122: @responsesfrom << node
123: rescue
124: @responsesfrom = [node]
125: 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 129
129: def report(caption = "rpc stats", verbose = false)
130: result_text = []
131:
132: if verbose
133: result_text << Helpers.colorize(:yellow, "---- #{caption} ----")
134:
135: if @discovered
136: @responses < @discovered ? color = :red : color = :reset
137: result_text << " Nodes: %s / %s" % [ Helpers.colorize(color, @discovered), Helpers.colorize(color, @responses) ]
138: else
139: result_text << " Nodes: #{@responses}"
140: end
141:
142: @failcount < 0 ? color = :red : color = :reset
143:
144: result_text << " Pass / Fail: %s / %s" % [Helpers.colorize(color, @okcount), Helpers.colorize(color, @failcount) ]
145: result_text << " Start Time: %s" % [Time.at(@starttime)]
146: result_text << " Discovery Time: %.2fms" % [@discoverytime * 1000]
147: result_text << " Agent Time: %.2fms" % [@blocktime * 1000]
148: result_text << " Total Time: %.2fms" % [@totaltime * 1000]
149: else
150: if @discovered
151: @responses < @discovered ? color = :red : color = :green
152:
153: result_text << "Finished processing %s / %s hosts in %.2f ms" % [Helpers.colorize(color, @responses), Helpers.colorize(color, @discovered), @blocktime * 1000]
154: else
155: result_text << "Finished processing %s hosts in %.2f ms" % [Helpers.colorize(:bold, @responses), @blocktime * 1000]
156: end
157: end
158:
159: if no_response_report != ""
160: result_text << "" << no_response_report
161: end
162:
163: result_text.join("\n")
164: end
Resets stats, if discovery time is set we keep it as it was
# File lib/mcollective/rpc/stats.rb, line 13
13: def reset
14: @noresponsefrom = []
15: @responsesfrom = []
16: @responses = 0
17: @starttime = Time.now.to_f
18: @discoverytime = 0 unless @discoverytime
19: @blocktime = 0
20: @totaltime = 0
21: @discovered = 0
22: @discovered_nodes = []
23: @okcount = 0
24: @failcount = 0
25: @noresponsefrom = []
26: end
helper to time block execution time
# File lib/mcollective/rpc/stats.rb, line 88
88: def time_block_execution(action)
89: if action == :start
90: @block_start = Time.now.to_f
91: elsif action == :end
92: @blocktime += Time.now.to_f - @block_start
93: else
94: raise("Uknown block action #{action}")
95: end
96: rescue
97: @blocktime = 0
98: end
Utility to time discovery from :start to :end
# File lib/mcollective/rpc/stats.rb, line 75
75: def time_discovery(action)
76: if action == :start
77: @discovery_start = Time.now.to_f
78: elsif action == :end
79: @discoverytime = Time.now.to_f - @discovery_start
80: else
81: raise("Uknown discovery action #{action}")
82: end
83: rescue
84: @discoverytime = 0
85: end
returns a hash of our stats
# File lib/mcollective/rpc/stats.rb, line 29
29: def to_hash
30: {:noresponsefrom => @noresponsefrom,
31: :starttime => @starttime,
32: :discoverytime => @discoverytime,
33: :blocktime => @blocktime,
34: :responses => @responses,
35: :totaltime => @totaltime,
36: :discovered => @discovered,
37: :discovered_nodes => @discovered_nodes,
38: :noresponsefrom => @noresponsefrom,
39: :okcount => @okcount,
40: :failcount => @failcount}
41: end