зеркало из https://github.com/microsoft/statsd.git
Merge pull request #195 from suvash/add-sets-example
Adds sets for Ruby example + Whitespace cleanup
This commit is contained in:
Коммит
d48f1b29e2
|
@ -5,8 +5,8 @@ require 'yaml'
|
|||
|
||||
# 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 @@ require 'yaml'
|
|||
|
||||
# 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 @@ class Statsd
|
|||
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 @@ class Statsd
|
|||
begin
|
||||
host = config["host"] || "localhost"
|
||||
port = config["port"] || "8125"
|
||||
|
||||
|
||||
sampled_data = {}
|
||||
if sample_rate < 1
|
||||
if rand <= sample_rate
|
||||
|
@ -67,7 +71,7 @@ class Statsd
|
|||
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 @@ class Statsd
|
|||
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче