Module: Mouth::Recorder
- Defined in:
- lib/mouth/recorder.rb
Overview
If you don’t want to use the Mouth daemon to collect UDP packets and write digests, you can use this to write metrics directly into mongo. IMPORTANT: You can’t use this + the daemon simultaneously for a given metric namespace.
Class Method Summary collapse
- .gauge(key, value) ⇒ Object
- .increment(key, delta = 1, sample_rate = nil) ⇒ Object
- .measure(key, milli = nil) ⇒ Object
Class Method Details
.gauge(key, value) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/mouth/recorder.rb', line 24 def gauge(key, value) ns, metric = Mouth.parse_key(key) collection = Mouth.collection_for(ns) t = Mouth. collection.update({"t" => t}, {"$set" => {"g.#{metric}" => value}}, :upsert => true) end |
.increment(key, delta = 1, sample_rate = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mouth/recorder.rb', line 8 def increment(key, delta = 1, sample_rate = nil) factor = 1.0 if sample_rate sample_rate = 1 if sample_rate > 1 return if rand > sample_rate factor = (sample_rate <= 0.0 || sample_rate > 1.0) ? 1.0 : 1.0 / sample_rate end ns, metric = Mouth.parse_key(key) collection = Mouth.collection_for(ns) t = Mouth. collection.update({"t" => t}, {"$inc" => {"c.#{metric}" => delta * factor}}, :upsert => true) end |
.measure(key, milli = nil) ⇒ Object
33 34 35 |
# File 'lib/mouth/recorder.rb', line 33 def measure(key, milli = nil) raise "Not implemented" end |