module Dalia::MiniGraphite
Constants
- DEFAULTS
- VERSION
Public Class Methods
benchmark_wrapper(key, result_send_method = nil) { || ... }
click to toggle source
# File lib/mini_graphite.rb, line 48 def self.benchmark_wrapper(key, result_send_method = nil) counter("#{key}.ini") result = nil time = Benchmark.realtime do result = yield end counter("#{key}.time", time * 1000) counter("#{key}.result", result.send(result_send_method)) if result_send_method counter("#{key}.end") time("#{key}.time_stats", time * 1000) result end
config(opts = {})
click to toggle source
# File lib/mini_graphite.rb, line 19 def self.config(opts = {}) @opts = DEFAULTS.merge(opts) @logger = Dalia::MiniGraphite::Logger.new(opts[:debug_mode]) logger.debug("Initalized with opts") logger.debug(opts.inspect) end
counter(key, value = nil)
click to toggle source
# File lib/mini_graphite.rb, line 33 def self.counter(key, value = nil) value ||= 1 signal = "#{key}:#{value}|c" logger.debug("Sending counter: '#{signal}'") send_udp(signal) if !opts[:mock_mode] end
datapoint(key, value = 1, timestamp = Time.now)
click to toggle source
# File lib/mini_graphite.rb, line 26 def self.datapoint(key, value = 1, timestamp = Time.now) signal = "#{key} #{value} #{timestamp.to_i}" logger.debug("Sending datapoint: '#{signal}'") send_tcp(signal) if !opts[:mock_mode] end
send_tcp(message)
click to toggle source
# File lib/mini_graphite.rb, line 67 def self.send_tcp(message) hosts = [opts[:graphite_host]].flatten hosts.each do |host| send_tcp_on_host(host, opts[:graphite_port], message) end end
send_tcp_on_host(host, port, message)
click to toggle source
# File lib/mini_graphite.rb, line 83 def self.send_tcp_on_host(host, port, message) socket = TCPSocket.new(host, port) socket.print("#{message}\n") socket.close end
send_udp(message)
click to toggle source
# File lib/mini_graphite.rb, line 75 def self.send_udp(message) hosts = [opts[:statsd_host]].flatten hosts.each do |host| send_udp_on_host(host, opts[:statsd_port], message) end end
send_udp_on_host(host, port, message)
click to toggle source
# File lib/mini_graphite.rb, line 89 def self.send_udp_on_host(host, port, message) socket = UDPSocket.new socket.send(message, 0, host, port) socket.close end
time(key, value = 0)
click to toggle source
# File lib/mini_graphite.rb, line 41 def self.time(key, value = 0) signal = "#{key}:#{value}|ms" logger.debug("Sending time: '#{signal}'") send_udp(signal) if !opts[:mock_mode] end
Private Class Methods
logger()
click to toggle source
# File lib/mini_graphite.rb, line 101 def self.logger @logger end
opts()
click to toggle source
# File lib/mini_graphite.rb, line 97 def self.opts @opts end