Class: Flamingo::Stats::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/flamingo/stats/events.rb

Constant Summary collapse

ALL_COUNT =
"events:all_count"
RATE =
"events:rate"
LAST_TIME =
"events:last_time"
TYPE_COUNT =
"events:%s_count"
TWEET_COUNT =
TYPE_COUNT % [:tweet]

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



11
12
13
14
15
16
# File 'lib/flamingo/stats/events.rb', line 11

def initialize
  @rate_counter = Flamingo::Stats::RateCounter.new(10) do |eps|
    meta.set(RATE,eps)
    logger.debug "%.3f eps" % [eps]
  end
end

Instance Method Details

#all_countObject



25
26
27
# File 'lib/flamingo/stats/events.rb', line 25

def all_count
  meta.get(ALL_COUNT) || 0
end

#event!(type) ⇒ Object



18
19
20
21
22
23
# File 'lib/flamingo/stats/events.rb', line 18

def event!(type)
  @rate_counter.event!
  meta.incr(ALL_COUNT)
  meta.set(LAST_TIME,Time.now.to_i)
  meta.incr(TYPE_COUNT % [type])    
end

#last_timeObject



29
30
31
# File 'lib/flamingo/stats/events.rb', line 29

def last_time
  meta.get(LAST_TIME)
end

#tweet_countObject



37
38
39
# File 'lib/flamingo/stats/events.rb', line 37

def tweet_count
  type_count(:tweet)
end

#type_count(type) ⇒ Object



33
34
35
# File 'lib/flamingo/stats/events.rb', line 33

def type_count(type)
  meta.get(TYPE_COUNT % [type]) || 0
end