JustinAiken / adhearsion-stats

Stats sending for Adhearsion
MIT License
3 stars 2 forks source link

Adhearsion Stats Build StatusCode ClimateCoverage Status

This is an Adhearsion plugin for sending metrics to a statsd server.

It uses the statsd gem.

Usage Example

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

Optional Logging

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)
...

Stat Types

Counters (#increment and #decrement)

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

Timers (#timing and #time)

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

Gauges (#gauge)

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

Links

Note on Patches/Pull Requests

Credits

Original author: JustinAiken

Developed for Mojo Lingo.

Copyright

Copyright (c) 2013 Adhearsion Foundation Inc. MIT license (see LICENSE for details).