class SemanticLogger::Metric::Statsd
def initialize(url: "udp://localhost:8125")
url: 'localhost:8125'
metric: :statsd,
SemanticLogger.add_appender(
Example:
Default: udp://localhost:8125
udp://localhost:8125/namespace
Example, send all metrics to a particular namespace:
udp://localhost:8125
Example:
Valid URL to post to.
url: [String]
Parameters:
Create Statsd metrics subscriber
def initialize(url: "udp://localhost:8125") @url = url super() end
def log(log)
def log(log) metric = log.metric if (duration = log.duration) @statsd.timing(metric, duration) else amount = (log.metric_amount || 1).round if amount.negative? amount.times { @statsd.decrement(metric) } else amount.times { @statsd.increment(metric) } end end end
def reopen
def reopen uri = URI.parse(@url) raise('Statsd only supports udp. Example: "udp://localhost:8125"') if uri.scheme != "udp" @statsd = ::Statsd.new(uri.host, uri.port) path = uri.path.chomp("/") @statsd.namespace = path.sub("/", "") if path != "" end
def should_log?(log)
def should_log?(log) # Does not support metrics with dimensions. log.metric && !log.dimensions && meets_log_level?(log) && !filtered?(log) end