Module: Vitals::Utils

Defined in:
lib/vitals/utils.rb

Constant Summary collapse

BAD_METRICS_CHARS =
Regexp.compile('[\/\-:\s]').freeze
SEPARATOR =
'.'.freeze

Class Method Summary collapse

Class Method Details

.grape_path(route) ⇒ Object

XXX grape specific, move this away some day?



15
16
17
18
19
20
21
22
# File 'lib/vitals/utils.rb', line 15

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

.hostnameObject



8
9
10
# File 'lib/vitals/utils.rb', line 8

def self.hostname
  `hostname -s`.chomp
end

.normalize_metric(m) ⇒ Object



5
6
7
# File 'lib/vitals/utils.rb', line 5

def self.normalize_metric(m)
  m.gsub(BAD_METRICS_CHARS, '_')
end

.path_sepObject



24
25
26
# File 'lib/vitals/utils.rb', line 24

def self.path_sep
  @path_sep
end

.path_sep=(val) ⇒ Object



28
29
30
# File 'lib/vitals/utils.rb', line 28

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

.sec_to_ms(sec) ⇒ Object



11
12
13
# File 'lib/vitals/utils.rb', line 11

def self.sec_to_ms(sec)
  (1000.0 * sec).round
end