Skip to content

Instantly share code, notes, and snippets.

@blurredbits
Created July 31, 2015 18:13
Show Gist options
  • Save blurredbits/db05490c5f9bcd09531a to your computer and use it in GitHub Desktop.
Save blurredbits/db05490c5f9bcd09531a to your computer and use it in GitHub Desktop.

Revisions

  1. blurredbits created this gist Jul 31, 2015.
    26 changes: 26 additions & 0 deletions statsd_timer_example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    require 'statsd-ruby'

    statsd = Statsd.new('localhost', 8125)

    # Single call to statsd timer.
    statsd.time("timer_data") do
    timer_data = 1 + Random.rand(6)
    puts timer_data
    sleep timer_data
    end

    # Multiple calls to statsd timer.
    10.times do
    statsd.time("timer_data") do
    timer_data = 1 + Random.rand(6)
    puts timer_data
    sleep timer_data
    end
    end

    # Statsd Timer call without a code block
    10.times do
    fake_data = 1 + Random.rand(6)
    puts fake_data
    statsd.timing "fake_timer_data", fake_data
    end