Class: MCollective::RPC::Stats

### Home Classes Methods

### In Files

- lib/mcollective/rpc/stats.rb

### Parent

Object

### Methods

- ::new
- #[]
- #client_stats=
- #discovered_agents
- #fail
- #finish_request
- #no_response_report
- #node_responded
- #ok
- #report
- #reset
- #text_for_aggregates
- #time_block_execution
- #time_discovery
- #to_hash

### Files

- COPYING
- README
- Rakefile
- PLACEHOLDER
- PLACEHOLDER

### Class/Module Index

Quicksearch

- MCollective
- MCollective::Agent
- MCollective::Agents
- MCollective::Aggregate
- MCollective::Aggregate::Base
- MCollective::Aggregate::Result
- MCollective::Aggregate::Result::Base
- MCollective::Aggregate::Result::CollectionResult
- MCollective::Aggregate::Result::NumericResult
- MCollective::Application
- MCollective::Applications
- MCollective::Client
- MCollective::Config
- MCollective::Connector
- MCollective::Connector::Base
- MCollective::DDL
- MCollective::DDLValidationError
- MCollective::Data
- MCollective::Data::Base
- MCollective::Data::Result
- MCollective::Discovery
- MCollective::Facts
- MCollective::Facts::Base
- MCollective::Generators
- MCollective::Generators::AgentGenerator
- MCollective::Generators::Base
- MCollective::Generators::DataGenerator
- MCollective::InvalidRPCData
- MCollective::Log
- MCollective::Logger
- MCollective::Logger::Base
- MCollective::Logger::Console_logger
- MCollective::Logger::File_logger
- MCollective::Logger::Syslog_logger
- MCollective::Matcher
- MCollective::Matcher::Parser
- MCollective::Matcher::Scanner
- MCollective::Message
- MCollective::MissingRPCData
- MCollective::MsgDoesNotMatchRequestID
- MCollective::MsgTTLExpired
- MCollective::NotTargettedAtUs
- MCollective::Optionparser
- MCollective::PluginManager
- MCollective::PluginPackager
- MCollective::PluginPackager::AgentDefinition
- MCollective::PluginPackager::StandardDefinition
- MCollective::RPC
- MCollective::RPC::ActionRunner
- MCollective::RPC::Agent
- MCollective::RPC::Audit
- MCollective::RPC::Client
- MCollective::RPC::Helpers
- MCollective::RPC::Progress
- MCollective::RPC::Reply
- MCollective::RPC::Request
- MCollective::RPC::Result
- MCollective::RPC::Stats
- MCollective::RPCAborted
- MCollective::RPCError
- MCollective::Registration
- MCollective::Registration::Base
- MCollective::Runner
- MCollective::RunnerStats
- MCollective::SSL
- MCollective::Security
- MCollective::Security::Base
- MCollective::SecurityValidationFailed
- MCollective::Shell
- MCollective::UnixDaemon
- MCollective::UnknownRPCAction
- MCollective::UnknownRPCError
- MCollective::Util
- MCollective::WindowsDaemon
- Array
- Dir
- Object
- String
- Symbol

No matching classes.

# MCollective::RPC::Stats

Class to wrap all the stats and to keep track of some timings

### Attributes

aggregate_summary[RW]
blocktime[RW]
ddl[RW]
discovered[RW]
discovered_nodes[RW]
discoverytime[RW]
failcount[RW]
noresponsefrom[RW]
okcount[RW]
requestid[RW]
responses[RW]
responsesfrom[RW]
starttime[RW]
totaltime[RW]

### Public Instance Methods

[](key) click to toggle source

Fake hash access to keep things backward compatible

    # File lib/mcollective/rpc/stats.rb, line 49
    def [](key)
      to_hash[key]
    rescue
      nil
    end

client_stats=(stats) click to toggle source

Re-initializes the object with stats from the basic client

    # File lib/mcollective/rpc/stats.rb, line 70
    def client_stats=(stats)
      @noresponsefrom = stats[:noresponsefrom]
      @responses = stats[:responses]
      @starttime = stats[:starttime]
      @blocktime = stats[:blocktime]
      @totaltime = stats[:totaltime]
      @requestid = stats[:requestid]
      @discoverytime = stats[:discoverytime] if @discoverytime == 0
    end

discovered_agents(agents) click to toggle source

Update discovered and discovered_nodes based on discovery results

    # File lib/mcollective/rpc/stats.rb, line 108
    def discovered_agents(agents)
      @discovered_nodes = agents
      @discovered = agents.size
    end

fail() click to toggle source

increment the count of failed hosts

    # File lib/mcollective/rpc/stats.rb, line 63
    def fail
      @failcount += 1
    rescue
      @failcount = 1
    end

finish_request() click to toggle source

Helper to calculate total time etc

    # File lib/mcollective/rpc/stats.rb, line 114
    def finish_request
      @totaltime = @blocktime + @discoverytime

      # figures out who we had no responses from
      dhosts = @discovered_nodes.clone
      @responsesfrom.each {|r| dhosts.delete(r)}
      @noresponsefrom = dhosts
    rescue
      @totaltime = 0
      @noresponsefrom = []
    end

no_response_report() click to toggle source

Returns a blob of text indicating what nodes did not respond

    # File lib/mcollective/rpc/stats.rb, line 207
    def no_response_report
      result_text = StringIO.new

      if @noresponsefrom.size > 0
        result_text.puts
        result_text.puts Util.colorize(:red, "No response from:")
        result_text.puts

        @noresponsefrom.sort.in_groups_of(3) do |c|
          result_text.puts "   %-30s%-30s%-30s" % c
        end

        result_text.puts
      end

      result_text.string
    end

node_responded(node) click to toggle source

Helper to keep track of who we received responses from

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

ok() click to toggle source

increment the count of ok hosts

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

report(caption = "rpc stats", summarize = true, verbose = false) click to toggle source

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

    # File lib/mcollective/rpc/stats.rb, line 157
    def report(caption = "rpc stats", summarize = true, verbose = false)
      result_text = []

      if verbose
          if @aggregate_summary.size > 0 && summarize
            result_text << text_for_aggregates
          else
            result_text << ""
          end

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

        if @discovered
          @responses < @discovered ? color = :red : color = :reset
          result_text << "           Nodes: %s / %s" % [ Util.colorize(color, @discovered), Util.colorize(color, @responses) ]
        else
          result_text << "           Nodes: #{@responses}"
        end

        @failcount < 0 ? color = :red : color = :reset

        result_text << "     Pass / Fail: %s / %s" % [Util.colorize(color, @okcount), Util.colorize(color, @failcount) ]
        result_text << "      Start Time: %s"      % [Time.at(@starttime)]
        result_text << "  Discovery Time: %.2fms"  % [@discoverytime * 1000]
        result_text << "      Agent Time: %.2fms"  % [@blocktime * 1000]
        result_text << "      Total Time: %.2fms"  % [@totaltime * 1000]
      else
        if @discovered
          @responses < @discovered ? color = :red : color = :green

          if @aggregate_summary.size > 0 && 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]
        end
      end

      if no_response_report != ""
        result_text << "" << no_response_report
      end

      result_text.join("\n")
    end

reset() click to toggle source

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

    # File lib/mcollective/rpc/stats.rb, line 14
    def reset
      @noresponsefrom = []
      @responsesfrom = []
      @responses = 0
      @starttime = Time.now.to_f
      @discoverytime = 0 unless @discoverytime
      @blocktime = 0
      @totaltime = 0
      @discovered = 0
      @discovered_nodes = []
      @okcount = 0
      @failcount = 0
      @noresponsefrom = []
      @requestid = nil
      @aggregate_summary = []
    end

text_for_aggregates() click to toggle source

    # File lib/mcollective/rpc/stats.rb, line 133
    def text_for_aggregates
      result = StringIO.new

      @aggregate_summary.each do |aggregate|
        output_item = aggregate.result[:output]

        begin
          action_interface = @ddl.action_interface(aggregate.action)
          display_as = action_interface[:output][output_item][:display_as]
        rescue
          display_as = output_item
        end

        result.puts Util.colorize(:bold, "Summary of %s:" % display_as)
        result.puts
        result.puts aggregate.to_s
        result.puts
      end

      result.string
    end

time_block_execution(action) click to toggle source

helper to time block execution time

    # File lib/mcollective/rpc/stats.rb, line 94
    def time_block_execution(action)
      if action == :start
        @block_start = Time.now.to_f
      elsif action == :end
        @blocktime += Time.now.to_f - @block_start
      else
        raise("Uknown block action #{action}")
      end
    rescue
      @blocktime = 0
    end

time_discovery(action) click to toggle source

Utility to time discovery from :start to :end

    # File lib/mcollective/rpc/stats.rb, line 81
    def time_discovery(action)
      if action == :start
        @discovery_start = Time.now.to_f
      elsif action == :end
        @discoverytime = Time.now.to_f - @discovery_start
      else
        raise("Uknown discovery action #{action}")
      end
    rescue
      @discoverytime = 0
    end

to_hash() click to toggle source

returns a hash of our stats

    # File lib/mcollective/rpc/stats.rb, line 32
    def to_hash
      {:noresponsefrom    => @noresponsefrom,
       :starttime         => @starttime,
       :discoverytime     => @discoverytime,
       :blocktime         => @blocktime,
       :responses         => @responses,
       :totaltime         => @totaltime,
       :discovered        => @discovered,
       :discovered_nodes  => @discovered_nodes,
       :noresponsefrom    => @noresponsefrom,
       :okcount           => @okcount,
       :requestid         => @requestid,
       :failcount         => @failcount,
       :aggregate_summary => @aggregate_summary}
    end

### Public Class Methods

new() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.