service-status 0.0.4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjZlYTdiZTI0NTllZjk1N2Y4NmVkNDRiNmUxNjQ5MjdjZmFlODM5Mw==
4
+ YmVlZTA1OTAxMTkyODIzMWJiMjQxMzcyOWJkZTMyNDBjZWM4MDAzOA==
5
5
  data.tar.gz: !binary |-
6
- ZTQzOTllY2E0NzkyMzM1YmJkZGZkN2E0ZTU2MjM4NTc1MWYzZGJmOQ==
6
+ YTEyNGU4YTc1NTI0YzhkOGIyNjliMzJmZDFkMzAzNTg5YTQyMzkzZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDVlY2YwYzdiNWMyMzM5MjM5MzVkOThkOWNmMTc2NDI1NWM3ZTc1M2I1ZjVm
10
- MWUzNDk5NDI1YmIxOWQxOWFiODY3OTBlM2UzNmYxYWRhNjA2YmUwNDdlNDUx
11
- OTlkNTkwMGE2ZTk2YTI1NTUxZTYxODdkNWY0NmQxNmJiMGFmOWE=
9
+ YzViN2U3YmNiMTJmNzljOTE3NTk1YTgwOGM1ZDc1MTc4NzY0NzU3M2YyOGIy
10
+ OTE4YTFlNzI1YzQ2NDRmYThkZmI5ZWEyYjAwZDc5MDkyMjc4MTA2YzNhOTk4
11
+ ZWE2ODhkNDE0YWEzYjljYzcwNThmNmRiZDQxNzdiYjZmZmQ1MzI=
12
12
  data.tar.gz: !binary |-
13
- NTlhM2JlOGYyZTNkZTllY2MzNjllZTBmYTUwODdiMGI1ODMzOGQ1NWUwNDI3
14
- NGE4NWY1YjE3NGZiMDQwNDU1ODJkYjcxNWY0NTg4MjA5ZTI5NzM1ZmM3ZTgw
15
- OTBlMjVmYmQ4NTk3MmFiNzFmMDMyODg4YmJjYzJkODQ4NjYwZjI=
13
+ ZTg2MjAyZGNjNzhhMWZmMTk5ZThkOTE4ZTk3OTg1ZDg0NDcyOThiMWRhODdm
14
+ MjZlZjRkNGY5MjNjOGZmOGY2ZjM0MTI5MDJmMDU4NmNiNzJhMjc5NjFjZjA3
15
+ YmExMGU4OTFjNjYzNGQxNGQ0OWNmNzA4YmUyOTQyNzUzM2QzNmM=
data/.rubocop.yml CHANGED
@@ -1,3 +1,10 @@
1
+ AllCops:
2
+ RunRailsCops: false
3
+ Exclude:
4
+ - 'spec/**/*'
5
+ - 'service-status.gemspec'
6
+ - 'vendor/**/*'
7
+
1
8
  Documentation:
2
9
  Enabled: false
3
10
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- service-status (0.0.4)
4
+ service-status (1.0.1)
5
5
  sys-filesystem (~> 1.1)
6
6
 
7
7
  GEM
@@ -9,10 +9,8 @@ GEM
9
9
  specs:
10
10
  addressable (2.3.8)
11
11
  ast (2.0.0)
12
- astrolabe (1.3.0)
13
- parser (>= 2.2.0.pre.3, < 3.0)
14
- celluloid (0.16.0)
15
- timers (~> 4.0.0)
12
+ astrolabe (1.3.1)
13
+ parser (~> 2.2)
16
14
  codeclimate-test-reporter (0.4.7)
17
15
  simplecov (>= 0.7.1, < 1.0.0)
18
16
  coderay (1.1.0)
@@ -20,11 +18,11 @@ GEM
20
18
  safe_yaml (~> 1.0.0)
21
19
  diff-lcs (1.2.5)
22
20
  docile (1.1.5)
23
- ffi (1.9.8)
21
+ ffi (1.9.10)
24
22
  formatador (0.2.5)
25
- guard (2.12.5)
23
+ guard (2.12.8)
26
24
  formatador (>= 0.2.4)
27
- listen (~> 2.7)
25
+ listen (>= 2.7, <= 4.0)
28
26
  lumberjack (~> 1.0)
29
27
  nenv (~> 0.1)
30
28
  notiffany (~> 0.0)
@@ -32,14 +30,12 @@ GEM
32
30
  shellany (~> 0.0)
33
31
  thor (>= 0.18.1)
34
32
  guard-compat (1.2.1)
35
- guard-rspec (4.5.0)
33
+ guard-rspec (4.6.2)
36
34
  guard (~> 2.1)
37
35
  guard-compat (~> 1.1)
38
36
  rspec (>= 2.99.0, < 4.0)
39
- hitimes (1.2.2)
40
- json (1.8.2)
41
- listen (2.10.0)
42
- celluloid (~> 0.16.0)
37
+ json (1.8.3)
38
+ listen (3.0.2)
43
39
  rb-fsevent (>= 0.9.3)
44
40
  rb-inotify (>= 0.9)
45
41
  lumberjack (1.0.9)
@@ -48,7 +44,7 @@ GEM
48
44
  notiffany (0.0.6)
49
45
  nenv (~> 0.1)
50
46
  shellany (~> 0.0)
51
- parser (2.2.2.2)
47
+ parser (2.2.2.6)
52
48
  ast (>= 1.1, < 3.0)
53
49
  powerpack (0.1.1)
54
50
  pry (0.10.1)
@@ -59,25 +55,25 @@ GEM
59
55
  rake (10.4.2)
60
56
  rb-fchange (0.0.6)
61
57
  ffi
62
- rb-fsevent (0.9.4)
58
+ rb-fsevent (0.9.5)
63
59
  rb-inotify (0.9.5)
64
60
  ffi (>= 0.5.0)
65
- rspec (3.2.0)
66
- rspec-core (~> 3.2.0)
67
- rspec-expectations (~> 3.2.0)
68
- rspec-mocks (~> 3.2.0)
69
- rspec-core (3.2.3)
70
- rspec-support (~> 3.2.0)
71
- rspec-expectations (3.2.1)
61
+ rspec (3.3.0)
62
+ rspec-core (~> 3.3.0)
63
+ rspec-expectations (~> 3.3.0)
64
+ rspec-mocks (~> 3.3.0)
65
+ rspec-core (3.3.2)
66
+ rspec-support (~> 3.3.0)
67
+ rspec-expectations (3.3.1)
72
68
  diff-lcs (>= 1.2.0, < 2.0)
73
- rspec-support (~> 3.2.0)
74
- rspec-mocks (3.2.1)
69
+ rspec-support (~> 3.3.0)
70
+ rspec-mocks (3.3.2)
75
71
  diff-lcs (>= 1.2.0, < 2.0)
76
- rspec-support (~> 3.2.0)
77
- rspec-support (3.2.2)
78
- rubocop (0.31.0)
72
+ rspec-support (~> 3.3.0)
73
+ rspec-support (3.3.0)
74
+ rubocop (0.32.1)
79
75
  astrolabe (~> 1.3)
80
- parser (>= 2.2.2.1, < 3.0)
76
+ parser (>= 2.2.2.5, < 3.0)
81
77
  powerpack (~> 0.1)
82
78
  rainbow (>= 1.99.1, < 3.0)
83
79
  ruby-progressbar (~> 1.4)
@@ -94,9 +90,7 @@ GEM
94
90
  ffi
95
91
  terminal-notifier-guard (1.6.4)
96
92
  thor (0.19.1)
97
- timecop (0.7.3)
98
- timers (4.0.1)
99
- hitimes
93
+ timecop (0.7.4)
100
94
  vcr (2.9.3)
101
95
  webmock (1.21.0)
102
96
  addressable (>= 2.3.6)
data/README.md CHANGED
@@ -36,7 +36,11 @@ rescue
36
36
  redis_ok = false
37
37
  end
38
38
 
39
- status.add_check('redis', redis_ok)
39
+ #Last argument 'description' is optional
40
+ status.add_check('redis', redis_ok, 'Can connect to Redis')
41
+
42
+ #Last argument 'description' is optional
43
+ status.add_stat('request_count', 100, 'Number of Requests')
40
44
 
41
45
  JSON.pretty_generate(status) # render as JSON as required
42
46
  ```
@@ -49,17 +53,23 @@ they are included in 'errors' as well.
49
53
 
50
54
  ```javascript
51
55
  {
52
- "name": "windows",
53
- "version": "3.11",
54
- "hostname": "clippy",
55
- "errors": [],
56
- "checks": [
57
- "redis"
58
- ],
59
- "timestamp": "2015-05-07 14:35:17",
60
- "uptime": "14d:23:11:21",
61
- "diskusage": "64%",
62
- "status": "online"
56
+ "name": "windows",
57
+ "version": "3.11",
58
+ "hostname": "clippy",
59
+ "stats": [{
60
+ "name": "request_count",
61
+ "value": 100,
62
+ "description": "Number of Requests"
63
+ }],
64
+ "checks": [{
65
+ "name": "redis",
66
+ "successful": true
67
+ "description": "Can connect to Redis"
68
+ }],
69
+ "timestamp": "2015-05-07 14:35:17",
70
+ "uptime": "14d:23:11:21",
71
+ "diskusage": "64%",
72
+ "status": "online"
63
73
  }
64
74
 
65
75
  ```
data/Rakefile CHANGED
@@ -24,10 +24,7 @@ task :test do
24
24
  end
25
25
 
26
26
  task :rubocop do
27
- RuboCop::RakeTask.new(:rubocop) do |task|
28
- task.patterns = ['lib/**/*.rb']
29
- task.fail_on_error = true
30
- end
27
+ RuboCop::RakeTask.new
31
28
  end
32
29
 
33
30
  task :gem do
@@ -8,7 +8,7 @@ require 'sys/filesystem'
8
8
 
9
9
  module ServiceStatus
10
10
  class Status
11
- attr_reader :name, :version, :hostname, :errors, :checks, :timestamp
11
+ attr_reader :name, :version, :hostname, :checks, :timestamp, :stats
12
12
 
13
13
  def initialize(name, version, boot_time)
14
14
  @boot_time = boot_time
@@ -17,23 +17,33 @@ module ServiceStatus
17
17
  @hostname = Socket.gethostname
18
18
  @checks = []
19
19
  @timestamp = Time.now.strftime('%Y-%m-%d %T')
20
+ @stats = []
20
21
  @errors = []
21
22
  end
22
23
 
23
- def add_check(name, ok)
24
- @checks << name
25
- @errors << name unless ok
24
+ def add_check(name, successful, description = nil)
25
+ check = { name: name, successful: successful }
26
+ check[:description] = description if description
27
+ @checks << check
28
+ @errors << name unless successful
26
29
  end
27
30
 
28
31
  def add_http_get_check(name, url)
29
- @checks << name
32
+ successful = true
30
33
  uri = URI(url)
31
34
  begin
32
35
  res = Net::HTTP.get_response(uri)
33
- @errors << name unless res.is_a?(Net::HTTPSuccess)
36
+ successful = res.is_a?(Net::HTTPSuccess)
34
37
  rescue
35
- @errors << name
38
+ successful = false
36
39
  end
40
+ add_check(name, successful)
41
+ end
42
+
43
+ def add_stat(name, value, description = nil)
44
+ stat = { name: name, value: value }
45
+ stat[:description] = description if description
46
+ @stats << stat
37
47
  end
38
48
 
39
49
  def status
@@ -63,7 +73,7 @@ module ServiceStatus
63
73
  name: name,
64
74
  version: version,
65
75
  hostname: hostname,
66
- errors: errors,
76
+ stats: stats,
67
77
  checks: checks,
68
78
  timestamp: timestamp,
69
79
  uptime: uptime,
@@ -87,7 +97,7 @@ module ServiceStatus
87
97
  end
88
98
 
89
99
  def filesystem
90
- @stats ||= Sys::Filesystem.stat('/')
100
+ @root_filesystem ||= Sys::Filesystem.stat('/')
91
101
  end
92
102
  end
93
103
  end
@@ -1,3 +1,3 @@
1
1
  module ServiceStatus
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -4,7 +4,14 @@ require 'timecop'
4
4
  require 'json'
5
5
 
6
6
  describe ServiceStatus::Status do
7
+
7
8
  before :each do
9
+ stats = double('stats')
10
+ allow(stats).to receive(:blocks) { '239189165' }
11
+ allow(stats).to receive(:blocks_available) { '106180000' }
12
+ allow(Sys::Filesystem).to receive(:stat).with('/') { stats }
13
+ @disk_usage = '55%'
14
+
8
15
  @version = '0.0.1'
9
16
  @hostname = Socket.gethostname
10
17
  @app_name = 'killer-app'
@@ -23,10 +30,6 @@ describe ServiceStatus::Status do
23
30
  expect(@instance.hostname).to eql @hostname
24
31
  end
25
32
 
26
- it 'errors' do
27
- expect(@instance.errors).to eql []
28
- end
29
-
30
33
  it 'checks' do
31
34
  expect(@instance.checks).to eql []
32
35
  end
@@ -74,10 +77,6 @@ describe ServiceStatus::Status do
74
77
  end
75
78
 
76
79
  it 'diskusage' do
77
- stats = double('stats')
78
- expect(stats).to receive(:blocks) { '239189165' }
79
- expect(stats).to receive(:blocks_available) { '106180000' }
80
- expect(Sys::Filesystem).to receive(:stat).with('/') { stats }
81
80
  expect(@instance.disk_usage).to eql '55%'
82
81
  end
83
82
 
@@ -88,43 +87,82 @@ describe ServiceStatus::Status do
88
87
  it 'to_json' do
89
88
  Timecop.freeze(Time.local(2015, 04, 29, 14, 52, 47))
90
89
  @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
91
- stats = double('stats')
92
- expect(stats).to receive(:blocks) { '239189165' }
93
- expect(stats).to receive(:blocks_available) { '106180000' }
94
- expect(Sys::Filesystem).to receive(:stat).with('/') { stats }
95
- disk_usage = '55%'
96
- expect(@instance.to_json).to eql "{\"name\":\"#{@app_name}\",\"version\":\"#{@version}\",\"hostname\":\"#{@hostname}\",\"errors\":[],\"checks\":[],\"timestamp\":\"2015-04-29 14:52:47\",\"uptime\":\"0d:00:00:00\",\"diskusage\":\"#{disk_usage}\",\"status\":\"online\"}"
90
+ expect(@instance.to_json).to eql %({"name":"#{@app_name}","version":"#{@version}","hostname":"#{@hostname}","stats":[],"checks":[],"timestamp":"2015-04-29 14:52:47","uptime":"0d:00:00:00","diskusage":"#{@disk_usage}","status":"online"})
97
91
  Timecop.return
98
92
  end
99
93
 
100
94
  describe 'add_check' do
101
95
  it 'had a check that was ok' do
102
- @instance.add_check('ElasticSearch', true)
103
- expect(@instance.checks).to eql ['ElasticSearch']
104
- expect(@instance.errors).to eql []
96
+ @instance.add_check('elasticsearch', true)
97
+ expect(@instance.checks).to eql [{ name: 'elasticsearch', successful: true }]
105
98
  expect(@instance.status).to eql 'online'
106
99
  end
107
100
 
108
101
  it 'had a check that failed' do
109
- @instance.add_check('ElasticSearch', false)
110
- expect(@instance.checks).to eql ['ElasticSearch']
111
- expect(@instance.errors).to eql ['ElasticSearch']
102
+ @instance.add_check('elasticsearch', false)
103
+ expect(@instance.checks).to eql [{ name: 'elasticsearch', successful: false }]
112
104
  expect(@instance.status).to eql 'offline'
113
105
  end
106
+
107
+ it 'supports check with description' do
108
+ @instance.add_check('elasticsearch', true, 'Can connect to Elasticsearch')
109
+ expect(@instance.checks).to eql [{ name: 'elasticsearch', successful: true, description: 'Can connect to Elasticsearch' }]
110
+ expect(@instance.status).to eql 'online'
111
+ end
112
+
113
+
114
+ it 'shown in json' do
115
+ Timecop.freeze(Time.local(2015, 04, 29, 14, 52, 47))
116
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
117
+ @instance.add_check('elasticsearch', true)
118
+ expect(@instance.to_json).to eql %({"name":"#{@app_name}","version":"#{@version}","hostname":"#{@hostname}","stats":[],"checks":[{"name":"elasticsearch","successful":true}],"timestamp":"2015-04-29 14:52:47","uptime":"0d:00:00:00","diskusage":"#{@disk_usage}","status":"online"})
119
+ Timecop.return
120
+ end
114
121
  end
115
122
 
116
123
  describe 'add_http_get_check', :vcr do
117
124
  it 'ok' do
118
125
  @instance.add_http_get_check('Responsys API', 'https://ws2.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl')
119
- expect(@instance.checks).to eql ['Responsys API']
120
- expect(@instance.errors).to eql []
126
+ expect(@instance.checks).to eql [{:name=>"Responsys API", :successful=>true}]
121
127
  end
122
128
 
123
129
  it 'fail' do
124
130
  @instance.add_http_get_check('Responsys API', 'https://foobar.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl')
125
- expect(@instance.checks).to eql ['Responsys API']
126
- expect(@instance.errors).to eql ['Responsys API']
131
+ expect(@instance.checks).to eql [{:name=>"Responsys API", :successful=>false}]
127
132
  expect(@instance.status).to eql 'offline'
128
133
  end
129
134
  end
135
+
136
+ describe 'add stat' do
137
+
138
+ it 'add one' do
139
+ @instance.add_stat('request_counts', 100, 'Number of Requests')
140
+ expect(@instance.stats).to eql [{ description: 'Number of Requests', name: 'request_counts', value: 100 }]
141
+ end
142
+
143
+ it 'add multiple' do
144
+ @instance.add_stat('request_counts', 100, 'Number of Requests')
145
+ @instance.add_stat('error_counts', 42, 'Number of errors')
146
+ expect(@instance.stats).to eql [
147
+ { description: 'Number of Requests', name: 'request_counts', value: 100 },
148
+ {:name=>"error_counts", :value=>42, :description=>"Number of errors"}
149
+ ]
150
+ end
151
+
152
+ it 'add without description' do
153
+ @instance.add_stat('request_counts', 100)
154
+ expect(@instance.stats).to eql [{ name: 'request_counts', value: 100 }]
155
+ end
156
+
157
+
158
+
159
+ it 'shown in json' do
160
+ Timecop.freeze(Time.local(2015, 04, 29, 14, 52, 47))
161
+ @instance = ServiceStatus::Status.new(@app_name, @version, Time.now)
162
+ @instance.add_stat('request_counts', 100, 'Number of Requests')
163
+ expect(@instance.to_json).to eql %({"name":"#{@app_name}","version":"#{@version}","hostname":"#{@hostname}","stats":[{"name":"request_counts","value":100,"description":"Number of Requests"}],"checks":[],"timestamp":"2015-04-29 14:52:47","uptime":"0d:00:00:00","diskusage":"#{@disk_usage}","status":"online"})
164
+ Timecop.return
165
+ end
166
+
167
+ end
130
168
  end
data/spec/spec_helper.rb CHANGED
@@ -22,10 +22,10 @@ require 'simplecov'
22
22
  SimpleCov.start
23
23
 
24
24
  SimpleCov.configure do
25
- minimum_coverage '100%'
25
+ minimum_coverage '100%'
26
26
  end
27
27
 
28
- require "codeclimate-test-reporter"
28
+ require 'codeclimate-test-reporter'
29
29
  CodeClimate::TestReporter.start
30
30
 
31
31
  require 'vcr'
@@ -43,7 +43,7 @@ VCR.configure do |c|
43
43
  c.configure_rspec_metadata!
44
44
  end
45
45
 
46
- WebMock.disable_net_connect!(:allow => "codeclimate.com")
46
+ WebMock.disable_net_connect!(allow: 'codeclimate.com')
47
47
 
48
48
  RSpec.configure do |config|
49
49
  # rspec-expectations config goes here. You can use an alternate
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Griffiths
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-08 00:00:00.000000000 Z
12
+ date: 2015-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sys-filesystem