Git Product home page Git Product logo

adhearsion-stats's Introduction

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

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

Credits

Original author: JustinAiken

Developed for Mojo Lingo.

Copyright

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

adhearsion-stats's People

Contributors

bklang avatar justinaiken avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bklang emcgee

adhearsion-stats's Issues

Namespace probes

I'm not sure if this belongs in the library hard-coded, should be config, or should be left up to the Application exclusively. But I did something like this to namespace my probes to make it easier to separate development from production. This module was mixed in so that every call go #gauge, #increment or #timing had prefixes:

module CoreUtility
  def gauge(*args)
    AdhearsionStats.gauge prefixed_label(args.shift), *args
  end

  def increment(*args)
    # Increment gets a special label so it shows up in Graphite at a similar
    # nesting level to timers and gauges
    AdhearsionStats.increment "counters.#{prefixed_label(args.shift)}", *args
  end

  def timing(*args)
    label = prefixed_label args.shift
    if block_given?
      start = Time.now
      yield
      value = Time.now - start
    else
      value = args.shift
    end
    AdhearsionStats.timing label, value
  end

  def prefixed_label(label)
    "#{Adhearsion.config.platform.environment}.#{node_name}.#{label}"
  end

  def node_name
    @node_name ||= Socket.gethostname.split('.').first
  end
end

Should hook into Adhearsion's Statistics class

Would be cool if there was an option to hook into Adhearsion::Statistics with this plugin, so that graphite could graph all those stats with no programming needed on the users part...

  • Perhaps monkey-patch these 4 methods
  • Or maybe alias Celluloid::Actor[:statistics] to Celluloid::Actor[:statistics_original] and insert our own Celluloid::Actor[:statistics] that also sends stats.
  • Or maybe leave the built in stats alone, and just register our own event handlers in a similar fashion..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.