class CliMetricCollector

Constants

VERSION

Attributes

endpoint[RW]
extra[R]
name[R]

Public Class Methods

capture(name, payload = {}) click to toggle source
# File lib/cli_metric_collector.rb, line 12
def self.capture(name, payload = {})
  new(name, payload).sendout
end
new(name, extra = {}) click to toggle source
# File lib/cli_metric_collector.rb, line 18
def initialize(name, extra = {})
  @name = name
  @extra = extra
end

Public Instance Methods

sendout() click to toggle source
# File lib/cli_metric_collector.rb, line 23
def sendout
  if self.class.endpoint
    pid = fork
    pid ? Process.detach(pid) : exec(command)
  else
    puts "CliMetricCollector is missing the endpoint, nothing sent" 
  end
end

Private Instance Methods

command() click to toggle source
# File lib/cli_metric_collector.rb, line 43
def command
  [
    "curl", 
    "-XPOST",
    "-H 'Content-Type: application/json'",
    "-d '#{json}'",
    self.class.endpoint,
    "> /dev/null 2>&1"
  ].join(" ")
end
data() click to toggle source
# File lib/cli_metric_collector.rb, line 39
def data
  { :name => name, :data => extra }
end
json() click to toggle source
# File lib/cli_metric_collector.rb, line 34
def json
  require "json"
  data.to_json
end