interface.rb |
|
---|---|
require 'singleton'
require 'fozzie/socket'
module Fozzie
class Interface
include Fozzie::Socket, Singleton |
|
Increments the given stat by one, with an optional sample rate
|
def increment(stat, sample_rate=1)
count(stat, 1, sample_rate)
end |
Decrements the given stat by one, with an optional sample rate
|
def decrement(stat, sample_rate=1)
count(stat, -1, sample_rate)
end |
Registers a count for the given stat, with an optional sample rate
|
def count(stat, count, sample_rate=1)
send(stat, count, 'c', sample_rate)
end |
Registers a timing (in ms) for the given stat, with an optional sample rate
|
def timing(stat, ms, sample_rate=1)
send(stat, ms, 'ms', sample_rate)
end |
Registers the time taken to complete a given block (in ms), with an optional sample rate
|
def time(stat, sample_rate=1)
stat = stat.flatten.join('.') if stat.kind_of?(Array)
start = Time.now
result = yield
timing(stat, ((Time.now - start) * 1000).round, sample_rate)
result
end |
Registers the time taken to complete a given block (in ms), with an optional sample rate
|
def time_to_do(stat, sample_rate=1, &block)
time_for(stat, sample_rate, &block)
end |
Registers the time taken to complete a given block (in ms), with an optional sample rate
|
def time_for(stat, sample_rate=1, &block)
time(stat, sample_rate, &block)
end |
Registers a commit
|
def commit
event :commit
end |
Registers a commit
|
def committed
commit
end |
Registers that the app has been built
|
def built
event :build
end |
Registers a build for the app
|
def build
built
end |
Registers a deployed status for the given app
|
def deployed(app = nil)
event :deploy, app
end |
Registers a deployment for the given app
|
def deploy(app = nil)
deployed(app)
end |
Registers an increment on the result of the given boolean
|
def increment_on(stat, perf, sample_rate=1)
key = "#{stat}.%s" % (perf ? "success" : "fail")
increment(key, sample_rate)
perf
end |
Register an event of any type
|
def event(type, app = nil)
stat = ["event", type.to_s, app].compact.join('.')
timing stat, Time.now.usec
end
end
end |