Class: RestfulMetrics::Client

Inherits:
Object
  • Object
show all
Extended by:
LogTools
Defined in:
lib/restful_metrics/client.rb

Constant Summary collapse

@@connection =
nil

Class Method Summary collapse

Methods included from LogTools

logger

Class Method Details

.add_compound_metric(fqdn, name, values, distinct_id = nil, timestamp = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/restful_metrics/client.rb', line 66

def add_compound_metric(fqdn, name, values, distinct_id=nil, timestamp=nil)
  params = Hash.new
  params[:compound_metric] = Hash.new
  params[:compound_metric][:fqdn] = fqdn
  params[:compound_metric][:name] = name
  params[:compound_metric][:values] = values

  unless distinct_id.nil?
    params[:compound_metric][:distinct_id] = distinct_id
  end

  unless timestamp.nil?
    raise InvalidTimestamp unless timestamp.respond_to?(:to_i)
    params[:compound_metric][:occurred_at] = timestamp.to_i
  end

  post(Endpoint.compound_metrics, params)
end

.add_metric(fqdn, name, value, distinct_id = nil, timestamp = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/restful_metrics/client.rb', line 47

def add_metric(fqdn, name, value, distinct_id=nil, timestamp=nil)
  params = Hash.new
  params[:metric] = Hash.new
  params[:metric][:fqdn] = fqdn
  params[:metric][:name] = name
  params[:metric][:value] = value

  unless distinct_id.nil?
    params[:metric][:distinct_id] = distinct_id
  end

  unless timestamp.nil?
    raise InvalidTimestamp unless timestamp.respond_to?(:to_i)
    params[:metric][:occurred_at] = timestamp.to_i
  end

  post(Endpoint.metrics, params)
end

.async=(async_flag) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/restful_metrics/client.rb', line 27

def async=(async_flag)
  # DelayedJob integration
  require 'delayed_job' if async_flag

  @@async = async_flag && (defined?(Delayed) != nil)
  @@connection.async = @@async if @@connection
end

.async?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/restful_metrics/client.rb', line 35

def async?
  @@async
end

.debug=(debug_flag) ⇒ Object



18
19
20
21
# File 'lib/restful_metrics/client.rb', line 18

def debug=(debug_flag)
  @@debug = debug_flag
  @@connection.debug = @@debug if @@connection
end

.debug?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/restful_metrics/client.rb', line 23

def debug?
  @@debug
end

.disabled=(disabled_flag) ⇒ Object



39
40
41
# File 'lib/restful_metrics/client.rb', line 39

def disabled=(disabled_flag)
  @@disabled = disabled_flag
end

.disabled?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/restful_metrics/client.rb', line 43

def disabled?
  @@disabled
end

.set_credentials(api_key) ⇒ Object



12
13
14
15
16
# File 'lib/restful_metrics/client.rb', line 12

def set_credentials(api_key)
  @@connection = Connection.new(api_key)
  self.debug = @@debug
  true
end