Sha256: 8b614f2974e4cd75b6649b3500297d6c66f9c828c4b0d4dedd2e448d104c7b0d

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'

module Traxor
  module Metric
    def self.count(name, value, tags = {})
      log("count##{name}=#{value} #{tag_string(tags)}")
    end

    def self.measure(name, value, tags = {})
      log("measure##{name}=#{value} #{tag_string(tags)}")
    end

    def self.sample(name, value, tags = {})
      log("sample##{name}=#{value} #{tag_string(tags)}")
    end

    def self.tag_string(tags)
      Hash(tags).merge(Traxor::Tags.all).map do |tag_name, tag_value|
        "tag##{tag_name}=#{tag_value}"
      end.join(' ')
    end

    def self.normalize_values(value)
      value.to_s.gsub(/::/, '.').underscore.strip
    end

    def self.log(string)
      logger.info(normalize_values(string))
    end

    def self.logger
      Traxor.logger
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
traxor-0.1.18 lib/traxor/metric.rb