Class: MCollective::RunnerStats

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/runnerstats.rb

Overview

Class to store stats about the mcollectived, it should live in the PluginManager so that agents etc can get hold of it and return the stats to callers

Instance Method Summary collapse

Constructor Details

#initializeRunnerStats

Returns a new instance of RunnerStats.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mcollective/runnerstats.rb', line 5

def initialize
  @starttime = Time.now.to_i
  @validated = 0
  @unvalidated = 0
  @filtered = 0
  @passed = 0
  @total = 0
  @replies = 0
  @ttlexpired = 0

  @mutex = Mutex.new
end

Instance Method Details

#filteredObject

Records a message that didnt pass the filters



31
32
33
34
# File 'lib/mcollective/runnerstats.rb', line 31

def filtered
  Log.debug("Incrementing filtered stat")
  @filtered += 1
end

#passedObject

Records a message that passed the filters



25
26
27
28
# File 'lib/mcollective/runnerstats.rb', line 25

def passed
  Log.debug("Incrementing passed stat")
  @passed += 1
end

#receivedObject

Records receipt of a message



48
49
50
51
# File 'lib/mcollective/runnerstats.rb', line 48

def received
  Log.debug("Incrementing total stat")
  @total += 1
end

#sentObject

Records sending a message



54
55
56
57
58
59
# File 'lib/mcollective/runnerstats.rb', line 54

def sent
  @mutex.synchronize do
    Log.debug("Incrementing replies stat")
    @replies += 1
  end
end

#to_hashObject

Returns a hash with all stats



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mcollective/runnerstats.rb', line 62

def to_hash
  stats = {
    :validated => @validated,
    :unvalidated => @unvalidated,
    :passed => @passed,
    :filtered => @filtered,
    :starttime => @starttime,
    :total => @total,
    :ttlexpired => @ttlexpired,
    :replies => @replies
  }

  reply = {
    :stats => stats,
    :threads => [],
    :pid => Process.pid,
    :times => {}
  }

  ::Process.times.each_pair {|k, v|
    k = k.to_sym
    reply[:times][k] = v
  }

  Thread.list.each do |t|
    reply[:threads] << t.inspect.to_s
  end

  reply[:agents] = Agents.agentlist
  reply
end

#ttlexpiredObject

Records a message that failed TTL checks



19
20
21
22
# File 'lib/mcollective/runnerstats.rb', line 19

def ttlexpired
  Log.debug("Incrementing ttl expired stat")
  @ttlexpired += 1
end

#unvalidatedObject



42
43
44
45
# File 'lib/mcollective/runnerstats.rb', line 42

def unvalidated
  Log.debug("Incrementing unvalidated stat")
  @unvalidated += 1
end

#validatedObject

Records a message that validated ok



37
38
39
40
# File 'lib/mcollective/runnerstats.rb', line 37

def validated
  Log.debug("Incrementing validated stat")
  @validated += 1
end