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

Methods

Attributes

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] 

Public Class methods

[Source]

    # File lib/mcollective/rpc/stats.rb, line 9
 9:       def initialize
10:         reset
11:       end

Public Instance methods

Fake hash access to keep things backward compatible

[Source]

    # 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

[Source]

    # 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

[Source]

     # 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

[Source]

    # 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

[Source]

     # 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

[Source]

     # File lib/mcollective/rpc/stats.rb, line 207
207:       def no_response_report
208:         result_text = StringIO.new
209: 
210:         if @noresponsefrom.size > 0
211:           result_text.puts
212:           result_text.puts Util.colorize(:red, "No response from:")
213:           result_text.puts
214: 
215:           @noresponsefrom.sort.in_groups_of(3) do |c|
216:             result_text.puts "   %-30s%-30s%-30s" % c
217:           end
218: 
219:           result_text.puts
220:         end
221: 
222:         result_text.string
223:       end

Helper to keep track of who we received responses from

[Source]

     # File lib/mcollective/rpc/stats.rb, line 127
127:       def node_responded(node)
128:         @responsesfrom << node
129:       rescue
130:         @responsesfrom = [node]
131:       end

increment the count of ok hosts

[Source]

    # File lib/mcollective/rpc/stats.rb, line 56
56:       def ok
57:         @okcount += 1
58:       rescue
59:         @okcount = 1
60:       end

Returns a blob of text representing the request status based on the stats contained in this class

[Source]

     # File lib/mcollective/rpc/stats.rb, line 157
157:       def report(caption = "rpc stats", summarize = true, verbose = false)
158:         result_text = []
159: 
160:         if verbose
161:             if @aggregate_summary.size > 0 && summarize
162:               result_text << text_for_aggregates
163:             else
164:               result_text << ""
165:             end
166: 
167:           result_text << Util.colorize(:yellow, "---- #{caption} ----")
168: 
169:           if @discovered
170:             @responses < @discovered ? color = :red : color = :reset
171:             result_text << "           Nodes: %s / %s" % [ Util.colorize(color, @discovered), Util.colorize(color, @responses) ]
172:           else
173:             result_text << "           Nodes: #{@responses}"
174:           end
175: 
176:           @failcount < 0 ? color = :red : color = :reset
177: 
178:           result_text << "     Pass / Fail: %s / %s" % [Util.colorize(color, @okcount), Util.colorize(color, @failcount) ]
179:           result_text << "      Start Time: %s"      % [Time.at(@starttime)]
180:           result_text << "  Discovery Time: %.2fms"  % [@discoverytime * 1000]
181:           result_text << "      Agent Time: %.2fms"  % [@blocktime * 1000]
182:           result_text << "      Total Time: %.2fms"  % [@totaltime * 1000]
183:         else
184:           if @discovered
185:             @responses < @discovered ? color = :red : color = :green
186: 
187:             if @aggregate_summary.size > 0 && summarize
188:               result_text << text_for_aggregates
189:             else
190:               result_text << ""
191:             end
192: 
193:             result_text << "Finished processing %s / %s hosts in %.2f ms" % [Util.colorize(color, @responses), Util.colorize(color, @discovered), @blocktime * 1000]
194:           else
195:             result_text << "Finished processing %s hosts in %.2f ms" % [Util.colorize(:bold, @responses), @blocktime * 1000]
196:           end
197:         end
198: 
199:         if no_response_report != ""
200:           result_text << "" << no_response_report
201:         end
202: 
203:         result_text.join("\n")
204:       end

Resets stats, if discovery time is set we keep it as it was

[Source]

    # 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

[Source]

     # 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:           result.puts Util.colorize(:bold, "Summary of %s:" % display_as)
147:           result.puts
148:           result.puts aggregate.to_s
149:           result.puts
150:         end
151: 
152:         result.string
153:       end

helper to time block execution time

[Source]

     # 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

[Source]

    # 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

[Source]

    # 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

[Validate]