Sha256: 0039f14e033026631cfd99ef308622f28f2762ccfe83a9aa8fef3d86a99fb038

Contents?: true

Size: 841 Bytes

Versions: 7

Compression:

Stored size: 841 Bytes

Contents

module Vitals
  module Utils
    BAD_METRICS_CHARS = Regexp.compile('[\/\-:\s]').freeze
    SEPARATOR = '.'.freeze
    def self.normalize_metric(m)
      m.gsub(BAD_METRICS_CHARS, '_')
    end
    def self.hostname
      `hostname -s`.chomp
    end
    def self.sec_to_ms(sec)
      (1000.0 * sec).round
    end
    # XXX grape specific, move this away some day?
    def self.grape_path(route)
      version = route.route_version
      path = route.route_path.dup[1..-1]          # /foo/bar/baz -> foo/bar/baz
      path.sub!(/\(\..*\)$/, '')                  # (.json) -> ''
      path.sub!(":version", version) if version   # :version -> v1
      path.gsub!(/\//, self.path_sep)     # foo/bar -> foo.bar
      path
    end

    def self.path_sep
      @path_sep
    end

    def self.path_sep=(val)
      @path_sep = val
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vitals-0.11.1 lib/vitals/utils.rb
vitals-0.11.0 lib/vitals/utils.rb
vitals-0.10.1 lib/vitals/utils.rb
vitals-0.10.0 lib/vitals/utils.rb
vitals-0.9.1 lib/vitals/utils.rb
vitals-0.9.0 lib/vitals/utils.rb
vitals-0.8.1 lib/vitals/utils.rb