lib/fozzie/interface.rb in fozzie-0.0.27 vs lib/fozzie/interface.rb in fozzie-1.0.0
- old
+ new
@@ -1,11 +1,9 @@
-require 'singleton'
-require 'fozzie/socket'
+require 'fozzie/adapter/statsd'
module Fozzie
- class Interface
- include Fozzie::Socket, Singleton
+ module Interface
# Increments the given stat by one, with an optional sample rate
#
# `Stats.increment 'wat'`
def increment(stat, sample_rate=1)
@@ -21,18 +19,18 @@
# Registers a count for the given stat, with an optional sample rate
#
# `Stats.count 'wat', 500`
def count(stat, count, sample_rate=1)
- send(stat, count, 'c', sample_rate)
+ send(stat, count, :count, sample_rate)
end
# Registers a timing (in ms) for the given stat, with an optional sample rate
#
# `Stats.timing 'wat', 500`
def timing(stat, ms, sample_rate=1)
- send(stat, ms, 'ms', sample_rate)
+ send(stat, ms, :timing, sample_rate)
end
# Registers the time taken to complete a given block (in ms), with an optional sample rate
#
# `Stats.time 'wat' { # Do something... }`
@@ -45,11 +43,11 @@
# Registers the time taken to complete a given block (in ms), with an optional sample rate
#
# `Stats.time_to_do 'wat' { # Do something, again... }`
def time_to_do(stat, sample_rate=1, &block)
- time_for(stat, sample_rate, &block)
+ time(stat, sample_rate, &block)
end
# Registers the time taken to complete a given block (in ms), with an optional sample rate
#
# `Stats.time_for 'wat' { # Do something, grrr... }`
@@ -97,29 +95,46 @@
# `Stats.deploy 'watapp'`
def deploy(app = nil)
deployed(app)
end
+ # Register an event of any type
+ #
+ # `Stats.event 'wat', 'app'`
+ def event(type, app = nil)
+ gauge ["event", type.to_s, app], Time.now.usec
+ end
+
# Registers an increment on the result of the given boolean
#
# `Stats.increment_on 'wat', wat.random?`
def increment_on(stat, perf, sample_rate=1)
key = [stat, (perf ? "success" : "fail")]
increment(key, sample_rate)
perf
end
- # Register an event of any type
- #
- # `Stats.event 'wat', 'app'`
- def event(type, app = nil)
- gauge ["event", type.to_s, app], Time.now.usec
- end
-
# Register an arbitrary value
#
# `Stats.gauge 'wat', 'app'`
def gauge(stat, value, sample_rate = 1)
- send(stat, value, "g", sample_rate)
+ send(stat, value, :gauge, sample_rate)
end
+
+ # Register multiple statistics in a single call
+ #
+ # `Stats.bulk do
+ # increment 'wat'
+ # decrement 'wot'
+ # end`
+ def bulk(&block)
+ Fozzie::BulkDsl.new(&block)
+ end
+
+ private
+
+ def adapter
+ Fozzie.c.adapter
+ end
+
end
end
\ No newline at end of file