Class: Pingdom::Summary::Average

Inherits:
Base
  • Object
show all
Defined in:
lib/pingdom/summary/average.rb

Overview

summary.average includeuptime probes=34,35 byprobe { “responsetime”=>

  "from"=>0, "to"=>1298110456, "probes"=>"34, 35", "avgresponse"=>[
    {"probeid"=>35, "avgresponse"=>94,
    "avgresponse"=>125 ]},
"status"=>"totalunknown"=>1293069551, "totaldown"=>5078}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attributes, check_error!, #id, #initialize, #inspect, #method_missing, #respond_to?, #respond_to_missing?

Constructor Details

This class inherits a constructor from Pingdom::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pingdom::Base

Class Method Details

.parse(client, response) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pingdom/summary/average.rb', line 10

def self.parse(client, response)
  body = super["summary"]
  sum = body["responsetime"]
  attrs = sum.slice("from", "to")
  attrs["probes"] = (attrs["probes"] || "").gsub(/\w+/, "").split(",").map(&:to_i)

  sum["status"] = Status.new(client, response, body["status"]) if body.key?("status")

  case sum["avgresponse"]
  when Array
    sum["responsetime"] = 0
    sum["averages"] = sum.delete("avgresponse").map do |avg|
      sum["responsetime"] += avg["avgresponse"]
      new(client, response, avg)
    end
    sum["responsetime"] = sum["responsetime"] / sum["averages"].size if !sum["averages"].size.empty?

  when Integer
    sum["responsetime"] = sum.delete("avgresponse")
  end

  sum = Summary.new(client, response, sum)
end

Instance Method Details

#probeObject



37
38
39
# File 'lib/pingdom/summary/average.rb', line 37

def probe
  @client.probes.detect { |probe| probe.id == probe_id }
end