class Uptimr::Check

Attributes

availability[RW]
count[RW]
daily_stats[RW]
first_tested[RW]
hourly_stats[RW]
id[RW]
is_up[RW]
last_tested[RW]
monthly_stats[RW]
name[RW]
response_time[RW]
responsiveness[RW]
url[RW]

Public Class Methods

find(id) click to toggle source
# File lib/uptimr/check.rb, line 27
def self.find(id)
        self.new Uptimr.request "/api/checks/#{id}", method: :get
end
list() click to toggle source
# File lib/uptimr/check.rb, line 22
def self.list
        response = Uptimr.request "/api/checks", method: :get
        response.map { |check| self.new check }
end
new(params) click to toggle source
# File lib/uptimr/check.rb, line 9
def initialize(params)
        @id = params[:_id]
        @is_up = params[:isUp]
        @first_tested = Time.iso8601(params[:firstTested]).localtime
        @last_tested = Time.iso8601(params[:lastTested]).localtime
        @name = params[:name]
        @url = params[:url]
        @responsiveness = params[:qos][:responsiveness].to_f
        @response_time = params[:qos][:responseTime].to_f
        @availability = params[:qos][:availability].to_f
        @count = params[:qos][:count]
end

Public Instance Methods

get_daily_stats(from=0, to=Time.now) click to toggle source
# File lib/uptimr/check.rb, line 35
def get_daily_stats(from=0, to=Time.now)
        @daily_stats ||= Uptimr.request "/api/checks/#{@id}/stats/day?begin=#{to_ms from}&end=#{to_ms to}", method: :get
end
get_hourly_stats(from=0, to=Time.now) click to toggle source
# File lib/uptimr/check.rb, line 31
def get_hourly_stats(from=0, to=Time.now)
        @hourly_stats ||= Uptimr.request "/api/checks/#{@id}/stats/hour?begin=#{to_ms from}&end=#{to_ms to}", method: :get
end
get_monthly_stats(from=0, to=Time.now) click to toggle source
# File lib/uptimr/check.rb, line 39
def get_monthly_stats(from=0, to=Time.now)
        @monthly_stats ||= Uptimr.request "/api/checks/#{@id}/stats/month?begin=#{to_ms from}&end=#{to_ms to}", method: :get
end
reload_stats() click to toggle source
# File lib/uptimr/check.rb, line 43
def reload_stats
        get_hourly_stats if @hourly_stats.nil?
        get_daily_stats if @daily_stats.nil?
        get_monthly_stats if @monthly_stats.nil?
end

Private Instance Methods

to_ms(time) click to toggle source
# File lib/uptimr/check.rb, line 51
def to_ms(time)
        time.to_i * 1000
end