lib/fozzie/socket.rb in fozzie-0.0.16 vs lib/fozzie/socket.rb in fozzie-0.0.17
- old
+ new
@@ -4,16 +4,21 @@
RESERVED_CHARS_REGEX = /[\:\|\@]/
private
# Send the statistic to the server
+ #
+ # Creates the Statsd key from the given values, and sends to socket (depending on sample rate)
+ #
def send(stat, delta, type, sample_rate)
- prefix = "%s." % Fozzie.c.data_prefix unless Fozzie.c.data_prefix.nil?
- stat = stat.to_s.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
+ stat = [stat].flatten.compact.collect(&:to_s).join('.').downcase
+ stat = stat.gsub('::', '.').gsub(RESERVED_CHARS_REGEX, '_')
- k = "%s%s:%s|%s" % [prefix, stat, delta, type]
- k << '|@%s' % sample_rate.to_s if sample_rate < 1
+ k = [Fozzie.c.data_prefix, stat].compact.join('.')
+ k << ":"
+ k << [delta, type].join('|')
+ k << '@%s' % sample_rate.to_s if sample_rate < 1
sampled(sample_rate) { send_to_socket(k.strip) }
end
# If the statistic is sampled, generate a condition to check if it's good to send
@@ -28,10 +33,10 @@
Timeout.timeout(Fozzie.c.timeout) {
socket.send(message, 0, Fozzie.c.host, Fozzie.c.port)
true
}
rescue => exc
- Fozzie.ogger.debug {"Statsd Failure: #{exc.message}\n#{exc.backtrace}"} if Fozzie.logger
+ Fozzie.logger.debug {"Statsd Failure: #{exc.message}\n#{exc.backtrace}"} if Fozzie.logger
false
end
end
# The Socket we want to use to send data
\ No newline at end of file