This is an Adhearsion plugin for sending metrics to a statsd server.
It uses the statsd gem.
class WellTrackedCallController < Adhearsion::CallController before_call :start_stats after_call :end_stats def run answer ... hangup end private def start_stats @call_started = Time.now.to_f AdhearsionStats.increment "calls.started" AdhearsionStats.gauge "calls.in_progress", "+1" end def end_stats AdhearsionStats.gauge "calls.in_progress", "-1" #Track call duration in ms call_duration = Time.now.to_f - @call_started AdhearsionStats.timing "calls.length", (call_duration * 1000).to_i end end
If you set the
log_metrics option to true, it will generate a log file called
adhearsion-stats.log next to the
adhearsion.log showing every call send to statsd:
... 2014-01-14 01:08:53 PM: increment(foo) 2014-01-14 01:08:53 PM: timing(bar,100) ...
Either increments or decrements a simple counter. Mostly used for checking rate of things happening. By default will go up or down one, but you can also pass a value to increment a set amount:
AdhearsionStats.increment "foo", 10
Besides timing, can also be used for percents:
6.times do AdhearsionStats.timing "foo", 100 end 4.times do AdhearsionStats.timing "foo", 0 end # Sixty percent of the time, it works every time!
A block method is also available if you want to time an action:
AdhearsionStats.time "time_spent_in_menu" do menu menu_message do ... end end
Used to track running counts of something - these aren't reset each flush period.
AdhearsionStats.gauge "foo", +4 #This now goes up 4 and stays up 4 until the next time the gauge is sent something
Note on Patches/Pull Requests
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit, do not mess with Rakefile, version, or history.
- If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
- Send me a pull request. Bonus points for topic branches.
Original author: JustinAiken
Developed for Mojo Lingo.
Copyright (c) 2013 Adhearsion Foundation Inc. MIT license (see LICENSE for details).