Class: RServiceBus::StatisticManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/StatisticManager.rb

Overview

Used to collect various run time stats for runtime reporting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ StatisticManager

Returns a new instance of StatisticManager.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rservicebus/StatisticManager.rb', line 8

def initialize( host )
       @host = host
	@hash = Hash.new

	@totalProcessed = 0
	@totalErrored = 0
	@totalSent = 0
	@totalPublished = 0
	@totalReply = 0

	@totalByMessageType = Hash.new
       
       @output = !RServiceBus.getValue( 'VERBOSE', nil ).nil?
       @maxStatOutputCountdown = RServiceBus.getValue( 'STAT_OUTPUT_COUNTDOWN', '1').to_i
       @statOutputCountdown = 0
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/rservicebus/StatisticManager.rb', line 6

def output
  @output
end

Instance Method Details

#getForReporting2Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rservicebus/StatisticManager.rb', line 61

def getForReporting2
    if @written == false then
        @written = true
        types = Hash.new(0)
        ObjectSpace.each_object do|obj|
            types[obj.class]+=1
        end

        return types
    end
end

#getForReporting9Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rservicebus/StatisticManager.rb', line 73

def getForReporting9
	string = "T:#{@totalProcessed};E:#{@totalErrored};S:#{@totalSent};P:#{@totalPublished};R:#{@totalReply}"

#		if @hash.length > 0 then
#			@hash.each do |k,v|
#				string = "#{string};#{k}:#{v}"
#			end
#		end
	
	return string
end

#inc(key) ⇒ Object



45
46
47
48
49
50
# File 'lib/rservicebus/StatisticManager.rb', line 45

def inc( key )
	if @hash[key].nil? then
		@hash[key] = 0
	end
	@hash[key] = @hash[key] + 1
end

#incMessageType(className) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/rservicebus/StatisticManager.rb', line 52

def incMessageType( className )
	if @totalByMessageType[className].nil? then
		@totalByMessageType[className] = 1
	else
		@totalByMessageType[className] = @totalByMessageType[className] + 1
	end

end

#incTotalErroredObject



29
30
31
# File 'lib/rservicebus/StatisticManager.rb', line 29

def incTotalErrored
	@totalErrored = @totalErrored + 1
end

#incTotalProcessedObject



25
26
27
# File 'lib/rservicebus/StatisticManager.rb', line 25

def incTotalProcessed
	@totalProcessed = @totalProcessed + 1
end

#incTotalPublishedObject



37
38
39
# File 'lib/rservicebus/StatisticManager.rb', line 37

def incTotalPublished
	@totalPublished = @totalPublished + 1
end

#incTotalReplyObject



41
42
43
# File 'lib/rservicebus/StatisticManager.rb', line 41

def incTotalReply
	@totalReply = @totalReply + 1
end

#incTotalSentObject



33
34
35
# File 'lib/rservicebus/StatisticManager.rb', line 33

def incTotalSent
	@totalSent = @totalSent + 1
end

#reportObject



85
86
87
88
89
# File 'lib/rservicebus/StatisticManager.rb', line 85

def report
    if @output then
        @host.log( self.getForReporting9 )
    end
end

#tickObject



91
92
93
94
95
96
97
# File 'lib/rservicebus/StatisticManager.rb', line 91

def tick
    @statOutputCountdown = @statOutputCountdown - 1
    if @statOutputCountdown <= 0 then
        self.report
        @statOutputCountdown = @maxStatOutputCountdown
    end
end