downtime 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +3 -3
- data/lib/downtime.rb +33 -16
- data/lib/downtime/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDM1MGM3MDA5MTJhNTc2OTVjNDNhMjIxM2FkYjllMDdkZDEwYWVhYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e98457b64dba43ca15dabec94cf3020542e19760
|
4
|
+
data.tar.gz: 3d36aeafe269ea93ead1aa77e960043e2fd4bb76
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZGNjZjRiNjA1ZWQ2ZDg0MzJmZWU3ZDUwMTE5MmM3NjVkNmUxNmE1OTI5YzM3
|
11
|
-
ZjZkMzNjMWZhYTJhOTM3ZmQ0NmU4ZTE1MTFlMTc2OGUxOTFlZDQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDZkODQwOGU3YmVjMTJkZmFhYmJlZDY0YTFjNTc1NTEzYzZjN2QxNTZkNzEy
|
14
|
-
MTViYTU2YzVkZTkwMmFmNDJiZTUxOTkwZDBiMWI0NTIwMDE4NmJlMmQ0Mzli
|
15
|
-
ZjZjZWNkMzAzYmNlNjhhYjYxZGQ1YjdjMDFkY2E3OWJhMmM1MGE=
|
6
|
+
metadata.gz: 982921b1f752759e99d3e4e763b67e8d0b267d9ee34d9d33ea844696a732fa9f06e094a197eef206291ecded511eaa0afe8440ad6b21197c5243ecfdef5bde3b
|
7
|
+
data.tar.gz: 816122b302e54164f33a23c2fbd737b93b3311ee180e33805846a4516f12008d3a1bd93bc62b981d2c02f99f410d7fd493723964eafb7c9bcb92d4fe430e8cf1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Downtime
|
2
2
|
|
3
|
-
`downtime` checks your connection to a host (`8.8.8.8`) and aggregates the up- or downtimes (connection or no connection) in a file in a human readable format. Connection is made via a call to `dig +time=1 +tries=1 8.8.8.8`, so your ruby process needs to be able to call that command - although it would be really easy to change which tool is used.
|
3
|
+
`downtime` checks your connection to a host (`8.8.8.8`) and aggregates the up- or downtimes (connection or no connection) in a file in a human readable format. Connection is made via a call to `dig +time=1 +tries=1 8.8.8.8` and `wget -q -t 1 --timeout 1 --spider http://siebenlinden.de`, so your ruby process needs to be able to call that command - although it would be really easy to change which tool is used.
|
4
4
|
|
5
5
|
It was made to track e.g. outages of your ISP.
|
6
6
|
|
@@ -25,9 +25,9 @@ Or install it yourself as:
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
Call as `downtime`.
|
28
|
-
It will create a `
|
28
|
+
It will create a `downtime_wget.log` and a `downtime_dig.log` file in the current working directory.
|
29
29
|
|
30
|
-
The
|
30
|
+
The files (`downtime_*.log`) will look like this:
|
31
31
|
|
32
32
|
# This file was generated by the downtime ruby gem.
|
33
33
|
2015-01-01-10-22 up till 2015-01-02-08-10 (1000 minutes)
|
data/lib/downtime.rb
CHANGED
@@ -3,26 +3,34 @@ require "downtime/timestamp"
|
|
3
3
|
|
4
4
|
module Downtime
|
5
5
|
class DowntimeCheck
|
6
|
+
attr_accessor :ip
|
6
7
|
attr_accessor :host
|
7
8
|
attr_accessor :log_file
|
8
9
|
|
9
10
|
def initialize
|
10
|
-
@
|
11
|
-
@
|
11
|
+
@ip = "8.8.8.8"
|
12
|
+
@host = "http://siebenlinden.de"
|
13
|
+
@log_file_dig = "downtime_dig.log"
|
14
|
+
@log_file_wget = "downtime_wget.log"
|
12
15
|
end
|
13
16
|
|
14
17
|
def perform
|
15
|
-
|
18
|
+
ensure_logfiles
|
16
19
|
timestamp!
|
17
|
-
|
20
|
+
check_and_update_files
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
21
24
|
|
22
|
-
def
|
23
|
-
|
25
|
+
def check_and_update_files
|
26
|
+
check_and_update_file(@log_file_dig, &method(:is_up_dig?))
|
27
|
+
check_and_update_file(@log_file_wget, &method(:is_up_wget?))
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_and_update_file(log_file, &check_mthd)
|
31
|
+
lines = File.readlines log_file
|
24
32
|
was_down = lines[-1] =~ /down/
|
25
|
-
up =
|
33
|
+
up = check_mthd.call
|
26
34
|
minutes = 0
|
27
35
|
if lines.length > 1
|
28
36
|
first_timestamp = lines[-1][/^[0-9-]*/]
|
@@ -50,29 +58,38 @@ module Downtime
|
|
50
58
|
lines << "#{@timestamp} down till #{@timestamp}"
|
51
59
|
end
|
52
60
|
end
|
53
|
-
File.open(
|
61
|
+
File.open(log_file, 'w') do |f|
|
54
62
|
f.puts lines
|
55
63
|
end
|
56
64
|
up
|
57
65
|
end
|
58
66
|
|
59
|
-
def
|
60
|
-
|
61
|
-
dig = `dig +time=1 +tries=1 #{
|
67
|
+
def is_up_dig? ip=nil
|
68
|
+
ip = @ip if ip.nil?
|
69
|
+
dig = `dig +time=1 +tries=1 #{ip}`
|
62
70
|
dig.lines.find {|l| l =~ /time.*ms/}
|
63
71
|
end
|
64
72
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
73
|
+
def is_up_wget? host=nil
|
74
|
+
host = @host if host.nil?
|
75
|
+
wget = `wget -q -t 1 --timeout 1 --spider #{host}`
|
76
|
+
return $?.exitstatus
|
77
|
+
end
|
78
|
+
|
79
|
+
def ensure_logfiles
|
80
|
+
return if(File.exist?(@log_file_dig) && File.exist?(@log_file_wget))
|
81
|
+
append_to_logfiles "# This file is created by the downtime #{Downtime::VERSION} ruby gem."
|
68
82
|
end
|
69
83
|
|
70
84
|
def timestamp!
|
71
85
|
@timestamp = Timestamp.new
|
72
86
|
end
|
73
87
|
|
74
|
-
def
|
75
|
-
File.open(@
|
88
|
+
def append_to_logfiles text
|
89
|
+
File.open(@log_file_wget, 'a') do |f|
|
90
|
+
f.puts text
|
91
|
+
end
|
92
|
+
File.open(@log_file_dig, 'a') do |f|
|
76
93
|
f.puts text
|
77
94
|
end
|
78
95
|
end
|
data/lib/downtime/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: downtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Wolfsteller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: Calls dig and updates up- and downtime information
|
@@ -46,7 +46,7 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- .gitignore
|
49
|
+
- ".gitignore"
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE.txt
|
52
52
|
- README.md
|
@@ -67,17 +67,17 @@ require_paths:
|
|
67
67
|
- lib
|
68
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
|
-
- -
|
70
|
+
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.4.6
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Monitors your internet connection
|