8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/dashing-contrib/jobs/pingdom_uptime.rb', line 8
def self.metrics(options)
client = DashingContrib::Pingdom::Client.new(
username: options[:username],
password: options[:password],
api_key: options[:api_key],
team_account: options[:team_account]
)
user_opt = self.default_date_ranges.merge(options)
id = user_opt[:check_id]
current_uptime = client.uptime(id, user_opt[:default_date_range], user_opt[:now])
first_uptime = client.uptime(id, user_opt[:first_date_range], user_opt[:now])
second_uptime = client.uptime(id, user_opt[:second_date_range], user_opt[:now])
status = client.checks(id)
if status[:check][:lasterrortime].nil?
last_down = "never"
else
last_down = ::DashingContrib::Time.readable_diff(::Time.at(status[:check][:lasterrortime]))
end
{
current: current_uptime.to_s,
first: first_uptime.to_s,
first_title: user_opt[:first_title],
second: second_uptime.to_s,
second_title: user_opt[:second_title],
is_up: status[:check][:status] == 'up',
current_response_time: status[:check][:lastresponsetime],
last_downtime: last_down
}
end
|