Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #195 from suvash/add-sets-example

Adds sets for Ruby example + Whitespace cleanup
  • Loading branch information...
commit d48f1b29e2e4bf8f87f3f0cad16180b4efeff088 2 parents f7d7113 + eca4f06
@mrtazz mrtazz authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 examples/ruby_example2.rb
View
16 examples/ruby_example2.rb
@@ -5,8 +5,8 @@
# Ian Sefferman <iseff@iseff.com>
# http://www.iseff.com
-
-# If this is running in a Rails environment, will pick up config/statsd.yml.
+
+# If this is running in a Rails environment, will pick up config/statsd.yml.
# config/statsd.yml should look like:
# production:
# host: statsd.domain.com
@@ -24,7 +24,7 @@
# Sends statistics to the stats daemon over UDP
class Statsd
-
+
def self.timing(stats, time, sample_rate=1)
Statsd.update_stats(stats, time, sample_rate, 'ms')
end
@@ -41,6 +41,10 @@ def self.gauges(stats, value, sample_rate=1)
Statsd.update_stats(stats, value, sample_rate, 'g')
end
+ def self.sets(stats, value, sample_rate=1)
+ Statsd.update_stats(stats, value, sample_rate, 's')
+ end
+
def self.update_stats(stats, delta=1, sample_rate=1, metric='c')
stats = [stats].flatten
@@ -56,7 +60,7 @@ def self.send(data, sample_rate=1)
begin
host = config["host"] || "localhost"
port = config["port"] || "8125"
-
+
sampled_data = {}
if sample_rate < 1
if rand <= sample_rate
@@ -67,7 +71,7 @@ def self.send(data, sample_rate=1)
else
sampled_data = data
end
-
+
udp = UDPSocket.new
sampled_data.each_pair do |stat, val|
send_data = "%s:%s" % [stat, val]
@@ -80,7 +84,7 @@ def self.send(data, sample_rate=1)
def self.config
return @@config if self.class_variable_defined?(:@@config)
- begin
+ begin
config_path = File.join(File.dirname(__FILE__), "statsd.yml")
# for Rails environments, check Rails.root/config/statsd.yml
if defined? Rails
Please sign in to comment.
Something went wrong with that request. Please try again.