sensu-plugins-rancher-service 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd66af46962dbd0edf412f8469ff73df0a69b9f4
4
- data.tar.gz: aaa3667a6a37a66431e04bb761e2591066a9d539
3
+ metadata.gz: ecd15143ee7c796993359fdb3ec314a246d0e91c
4
+ data.tar.gz: 943f0b833aa43e00c95a1b444c81bfe7fbd6dc2c
5
5
  SHA512:
6
- metadata.gz: 0efe09234e8f37c3c6f545a30e13b1dec35fef0b244aa60ace0e6b9d4f5daa2cec71d7bfa05a378e635ebbc7958f027cad21a286d0991942eee489a82a7530e7
7
- data.tar.gz: 38655493204550df98f1652b2deecaa6db0fa01540c7a6d043f8708cd61cd8b05d8dd345c45a234c89dc2eab1566c4d1170eb6b619d792db21bd650ad09fd5da
6
+ metadata.gz: bddaef888e41d5a2210a5ff9e940e3569dc6759fea3c32d94930d79c0ac7a5fe6fb93bc57c33f60dd0cd1674af39d8932fda78570cd9ee5280c299812e7ce750
7
+ data.tar.gz: f31ec907c036e90263383c1e79668145fdc01a737299457acd6d0b0cf7737ecf172059f44a19e60e73479dd1ed05e1ff29cce38a01526dcca3620de0797199d4
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [0.0.8] - 2016-01-17
9
+ ### Added
10
+ - Detecting when a service instance restarts
11
+ - Adding check on service state
12
+
8
13
  ## [0.0.7] - 2016-01-14
9
14
  ### Added
10
15
  - Added --handlers command line option
@@ -16,6 +16,11 @@ class CheckRancherService < Sensu::Plugin::Check::CLI
16
16
  :proc => proc { |s| s.gsub(/\/$/, '') },
17
17
  :default => "http://rancher-metadata/2015-07-25"
18
18
 
19
+ option :state_dir,
20
+ :description => "State directory",
21
+ :long => "--state-dir <PATH> (default: /var/cache/check-rancher-service)",
22
+ :default => "/var/cache/check-rancher-service"
23
+
19
24
  option :handlers,
20
25
  :description => "Comma separated list of handlers",
21
26
  :long => "--handlers <HANDLER>",
@@ -30,6 +35,23 @@ class CheckRancherService < Sensu::Plugin::Check::CLI
30
35
 
31
36
  def initialize()
32
37
  super
38
+
39
+ # prepare state directory
40
+ FileUtils.mkdir_p(config[:state_dir]) unless File.directory?(config[:state_dir])
41
+
42
+ @state_file = config[:state_dir] + "/containers.json"
43
+ end
44
+
45
+ def read_state()
46
+ if File.exists?(@state_file)
47
+ JSON.parse(File.read(@state_file))
48
+ else
49
+ {}
50
+ end
51
+ end
52
+
53
+ def write_state(state)
54
+ File.open(@state_file, 'w') { |f| f.write(state) }
33
55
  end
34
56
 
35
57
  def send_client_socket(data)
@@ -98,6 +120,9 @@ class CheckRancherService < Sensu::Plugin::Check::CLI
98
120
  unmonitored = 0
99
121
  unhealthy = 0
100
122
 
123
+ # read current state
124
+ state = read_state()
125
+
101
126
  get_services().each do |service|
102
127
  source = "#{service['stack_name']}_#{service['name']}.rancher.internal"
103
128
 
@@ -109,14 +134,31 @@ class CheckRancherService < Sensu::Plugin::Check::CLI
109
134
 
110
135
  # get containers
111
136
  service['containers'].each do |container_name|
112
- check_name = "rancher-container-#{container_name}-health_state"
137
+ check_name = "rancher-container-#{container_name}-state"
113
138
  msg = "Instance #{container_name}"
114
139
 
115
140
  unless monitored
116
141
  send_ok(check_name, source, "#{msg} not monitored (disabled)")
117
142
  else
118
- health_state = get_container(container_name)['health_state']
119
- case health_state
143
+ container = get_container(container_name)
144
+
145
+ skip = false
146
+ if state.has_key?(container_name)
147
+ if container['start_count'] > state[container_name]['start_count']
148
+ send_warning(check_name, source, "#{msg} has restarted"
149
+ skip = true
150
+ end
151
+ else
152
+ state[container_name] = {}
153
+ end
154
+
155
+ # update state
156
+ state[container_name]['start_count'] = container['start_count']
157
+
158
+ next if skip
159
+
160
+ # check if the service restarted
161
+ case container['health_state']
120
162
  when 'healthy'
121
163
  send_ok(check_name, source, "#{msg} is healthy")
122
164
 
@@ -132,6 +174,17 @@ class CheckRancherService < Sensu::Plugin::Check::CLI
132
174
  end
133
175
  end
134
176
 
177
+ # persist state to disk
178
+ write_state(state)
179
+
180
+ # check service scale size to determine whether it's degraded or not
181
+ check_name = "rancher-service-state"
182
+ if service['containers'].size < service['scale']
183
+ send_warning(check_name, source, "Service is in a degraded state - Current: #{service['containers'].size} (Scale: #{service['scale']})")
184
+ else
185
+ send_ok(check_name, source, "Service is healthy")
186
+ end
187
+
135
188
  critical("Found #{unhealthy} unhealthy instances") if unhealthy > 0
136
189
  warning("Found #{unmonitored} instances not begin monitored") if unmonitored > 0
137
190
  ok("All Rancher services instances are healthy")
@@ -2,7 +2,7 @@ module SensuPluginsRancherService
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 7
5
+ PATCH = 8
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-rancher-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin