Class: PingdomToGraphite::DataPull

Inherits:
Object
  • Object
show all
Defined in:
lib/pingdom-to-graphite/data-pull.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, key, log_level = Logger::ERROR) ⇒ DataPull

Returns a new instance of DataPull.



8
9
10
11
12
13
14
15
16
# File 'lib/pingdom-to-graphite/data-pull.rb', line 8

def initialize(username, password, key, log_level = Logger::ERROR)
  @username   = username
  @password   = password
  @key        = key
  @log_level  = log_level

  @client = connect

end

Instance Method Details

#check(id) ⇒ Object



39
40
41
# File 'lib/pingdom-to-graphite/data-pull.rb', line 39

def check(id)
  check_details = @client.check(id)
end

#checksObject



35
36
37
# File 'lib/pingdom-to-graphite/data-pull.rb', line 35

def checks
  check_list = @client.checks
end

#effective_limitObject

Return the lower of the two API limits



19
20
21
22
23
24
25
# File 'lib/pingdom-to-graphite/data-pull.rb', line 19

def effective_limit
  # Catch-22: We want to maximize our API calls, but we don't have our limits until we make an API call.
  unless @client.limit
    @client.contacts
  end
  limit = @client.limit[:short][:remaining] > @client.limit[:long][:remaining] ? @client.limit[:long][:remaining] : @client.limit[:short][:remaining]
end

#friendly_limitObject

A “Printer-friendly” version of the current limits



28
29
30
31
32
33
# File 'lib/pingdom-to-graphite/data-pull.rb', line 28

def friendly_limit
  limit = @client.limit
  short_time = Time.at(limit[:short][:resets_at] - Time.now).gmtime.strftime('%R:%S')
  long_time = Time.at(limit[:long][:resets_at] - Time.now).gmtime.strftime('%R:%S')
  "You can make #{limit[:short][:remaining]} requests in the next #{short_time} and #{limit[:long][:remaining]} requests in the next #{long_time}."
end

#full_results(check_id, start_ts, end_ts = nil, api_call_limit = 0) ⇒ Object

Get the full results for the range, looping over the API limits as necessary.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pingdom-to-graphite/data-pull.rb', line 67

def full_results(check_id, start_ts, end_ts = nil, api_call_limit = 0)
  offset = 0
  full_set = Array.new
  api_calls = 0
  # Loop until we either grab the full data set, run out of API calls, or hit the first check
  begin
    api_calls += 1
    result_set = self.results(check_id, start_ts, end_ts, offset)
    full_set = full_set.concat(result_set)
    offset += 100
  end until result_set.count < 100 || effective_limit < 10 || api_calls >= api_call_limit.to_i
  full_set
end

#probesObject



43
44
45
# File 'lib/pingdom-to-graphite/data-pull.rb', line 43

def probes
  probe_list = @client.probes
end

#results(check_id, start_ts = nil, end_ts = nil, offset = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pingdom-to-graphite/data-pull.rb', line 47

def results(check_id, start_ts = nil, end_ts = nil, offset = nil)

  check_options = {}

  unless start_ts.nil?
    check_options['from'] = start_ts
  end

  unless end_ts.nil?
    check_options['to'] = end_ts
  end

  unless offset.nil?
    check_options['offset'] = offset
  end

  results = @client.check(check_id).results(check_options)
end