sensu-plugins-docker 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eef23ca897def0a94dbd5b7484257f2c1e9ee5d
4
- data.tar.gz: bdd0a8001dd202895366694f64789458c99ca2d4
3
+ metadata.gz: d90fbbc20bfc21220fd34d813841ba8876ff0a19
4
+ data.tar.gz: 0a4ab98ea4bc07e046d350d41c07e80449c0196b
5
5
  SHA512:
6
- metadata.gz: 0241a1a73ecc658967ac7624940b43644edd18f732f2765640474a52e21a0a56f20a86fb107beb95452a413b7de21c1fffdc96e516f875e62891504f2d84b965
7
- data.tar.gz: a9595fe0a2d87f33b6e7dbe74439e65566d61bfde4e150d065624ca670bc4254644cc567b2522140af300d609b8d42278164d69a4bce84b4177e394c2de3109b
6
+ metadata.gz: 4ad7811845fb384e123e3a9bb65d02aafbed1fc30b363ea95fb18400638041e0b86c71b9594acfca5002dd6e8096e862ed5ed3c6a2b01d5cdb9af362560ef736
7
+ data.tar.gz: ee04d80ba6d787bef437922d897fb74e83f0cea1e22e03d3420872f77c9472ede8432ebec398b383df5a1d966c1d85563bbc0e3387071b954e282234f45cc673
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -3,7 +3,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
- ## Unreleased][unreleased]
6
+ ## Unreleased
7
+
8
+ ## [0.0.4] - 2015-08-10
9
+ ### Changed
10
+ - updated dependencies (added missing dependency `sys-proctable`)
11
+ - added docker metrics using docker api
7
12
 
8
13
  ## [0.0.3] - 2015-07-14
9
14
  ### Changed
@@ -20,4 +25,4 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
20
25
  - added binstubs
21
26
 
22
27
  ### Changed
23
- - removed cruft from /lib
28
+ - removed cruft from /lib
data/README.md CHANGED
@@ -18,6 +18,6 @@
18
18
 
19
19
  ## Installation
20
20
 
21
- [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
21
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
22
22
 
23
23
  ## Notes
@@ -0,0 +1,160 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # docker-container-metrics
4
+ #
5
+ # DESCRIPTION:
6
+ #
7
+ # Supports the stats feature of the docker remote api ( docker server 1.5 and newer )
8
+ # Currently only supports when docker is listening on tcp port.
9
+ #
10
+ #
11
+ # OUTPUT:
12
+ # metric-data
13
+ #
14
+ # PLATFORMS:
15
+ # Linux
16
+ #
17
+ # DEPENDENCIES:
18
+ # gem: sensu-plugin
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2015 Paul Czarkowski. Github @paulczar
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
32
+ require 'sensu-plugin/metric/cli'
33
+ require 'socket'
34
+ require 'net_http_unix'
35
+ require 'json'
36
+
37
+ class Hash
38
+ def self.to_dotted_hash(hash, recursive_key = '')
39
+ hash.each_with_object({}) do |(k, v), ret|
40
+ key = recursive_key + k.to_s
41
+ if v.is_a? Hash
42
+ ret.merge! to_dotted_hash(v, key + '.')
43
+ else
44
+ ret[key] = v
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
51
+ option :scheme,
52
+ description: 'Metric naming scheme, text to prepend to metric',
53
+ short: '-s SCHEME',
54
+ long: '--scheme SCHEME',
55
+ default: "#{Socket.gethostname}.docker"
56
+
57
+ option :container,
58
+ description: 'Name of container to collect metrics for',
59
+ short: '-c CONTAINER',
60
+ long: '--container CONTAINER',
61
+ default: ''
62
+
63
+ option :docker_host,
64
+ description: 'location of docker api, host:port or /path/to/docker.sock',
65
+ short: '-H DOCKER_HOST',
66
+ long: '--docker-host DOCKER_HOST',
67
+ default: '127.0.0.1:2375'
68
+
69
+ option :docker_protocol,
70
+ description: 'http or unix',
71
+ short: '-p PROTOCOL',
72
+ long: '--protocol PROTOCOL',
73
+ default: 'http'
74
+
75
+ option :friendly_names,
76
+ description: 'use friendly name if available',
77
+ short: '-n',
78
+ long: '--names',
79
+ boolean: true,
80
+ default: false
81
+
82
+ def run
83
+ @timestamp = Time.now.to_i
84
+
85
+ if config[:container] != ''
86
+ list = [config[:container]]
87
+ else
88
+ list = list_containers
89
+ end
90
+ list.each do |container|
91
+ stats = container_stats(container)
92
+ output_stats(container, stats)
93
+ end
94
+ ok
95
+ end
96
+
97
+ def output_stats(container, stats)
98
+ dotted_stats = Hash.to_dotted_hash stats
99
+ dotted_stats.each do |key, value|
100
+ next if key == 'read' # unecessary timestamp
101
+ next if key.start_with? 'blkio_stats' # array values, figure out later
102
+ output "#{config[:scheme]}.#{container}.#{key}", value, @timestamp
103
+ end
104
+ end
105
+
106
+ def docker_api(path)
107
+ if config[:docker_protocol] == 'unix'
108
+ begin
109
+ NetX::HTTPUnix.start("unix://#{config[:docker_host]}") do |http|
110
+ request = Net::HTTP::Get.new "/#{path}"
111
+ http.request request do |response|
112
+ response.read_body do |chunk|
113
+ @response = JSON.parse(chunk)
114
+ http.finish
115
+ end
116
+ end
117
+ end
118
+ rescue NoMethodError
119
+ # using http.finish to prematurely kill the stream causes this exception.
120
+ return @response
121
+ end
122
+ else
123
+ uri = URI("#{config[:docker_protocol]}://#{config[:docker_host]}/#{path}")
124
+ begin
125
+ Net::HTTP.start(uri.host, uri.port) do |http|
126
+ request = Net::HTTP::Get.new uri.request_uri
127
+ http.request request do |response|
128
+ response.read_body do |chunk|
129
+ @response = JSON.parse(chunk)
130
+ http.finish
131
+ end
132
+ end
133
+ end
134
+ rescue NoMethodError
135
+ # using http.finish to prematurely kill the stream causes this exception.
136
+ return @response
137
+ end
138
+ end
139
+ end
140
+
141
+ def list_containers
142
+ list = []
143
+ path = 'containers/json'
144
+ @containers = docker_api(path)
145
+
146
+ @containers.each do |container|
147
+ if config[:friendly_names]
148
+ list << container['Names'][0].gsub('/', '')
149
+ else
150
+ list << container['Id']
151
+ end
152
+ end
153
+ list
154
+ end
155
+
156
+ def container_stats(container)
157
+ path = "containers/#{container}/stats"
158
+ @stats = docker_api(path)
159
+ end
160
+ end
@@ -2,7 +2,7 @@ module SensuPluginsDocker
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,20 +30,20 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-07-14 00:00:00.000000000 Z
33
+ date: 2015-08-10 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: docker-api
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - '='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.21'
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - '='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.21'
49
49
  - !ruby/object:Gem::Dependency
@@ -61,89 +61,103 @@ dependencies:
61
61
  - !ruby/object:Gem::Version
62
62
  version: 1.2.0
63
63
  - !ruby/object:Gem::Dependency
64
- name: codeclimate-test-reporter
64
+ name: sys-proctable
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: '0.4'
70
- type: :development
69
+ version: 0.9.8
70
+ type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: '0.4'
76
+ version: 0.9.8
77
77
  - !ruby/object:Gem::Dependency
78
- name: rubocop
78
+ name: net_http_unix
79
79
  requirement: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - '='
82
82
  - !ruby/object:Gem::Version
83
- version: '0.30'
84
- type: :development
83
+ version: 0.2.1
84
+ type: :runtime
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - '='
89
89
  - !ruby/object:Gem::Version
90
- version: '0.30'
90
+ version: 0.2.1
91
91
  - !ruby/object:Gem::Dependency
92
- name: rspec
92
+ name: bundler
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '3.1'
97
+ version: '1.7'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '3.1'
104
+ version: '1.7'
105
105
  - !ruby/object:Gem::Dependency
106
- name: bundler
106
+ name: codeclimate-test-reporter
107
107
  requirement: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '1.7'
111
+ version: '0.4'
112
112
  type: :development
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '1.7'
118
+ version: '0.4'
119
119
  - !ruby/object:Gem::Dependency
120
- name: rake
120
+ name: github-markup
121
121
  requirement: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '10.0'
125
+ version: '1.3'
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '10.0'
132
+ version: '1.3'
133
133
  - !ruby/object:Gem::Dependency
134
- name: github-markup
134
+ name: pry
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '1.3'
139
+ version: '0.10'
140
140
  type: :development
141
141
  prerelease: false
142
142
  version_requirements: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: '1.3'
146
+ version: '0.10'
147
+ - !ruby/object:Gem::Dependency
148
+ name: rake
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '10.0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '10.0'
147
161
  - !ruby/object:Gem::Dependency
148
162
  name: redcarpet
149
163
  requirement: !ruby/object:Gem::Requirement
@@ -159,36 +173,51 @@ dependencies:
159
173
  - !ruby/object:Gem::Version
160
174
  version: '3.2'
161
175
  - !ruby/object:Gem::Dependency
162
- name: yard
176
+ name: rspec
163
177
  requirement: !ruby/object:Gem::Requirement
164
178
  requirements:
165
179
  - - "~>"
166
180
  - !ruby/object:Gem::Version
167
- version: '0.8'
181
+ version: '3.1'
168
182
  type: :development
169
183
  prerelease: false
170
184
  version_requirements: !ruby/object:Gem::Requirement
171
185
  requirements:
172
186
  - - "~>"
173
187
  - !ruby/object:Gem::Version
174
- version: '0.8'
188
+ version: '3.1'
175
189
  - !ruby/object:Gem::Dependency
176
- name: pry
190
+ name: rubocop
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '='
194
+ - !ruby/object:Gem::Version
195
+ version: 0.32.1
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - '='
201
+ - !ruby/object:Gem::Version
202
+ version: 0.32.1
203
+ - !ruby/object:Gem::Dependency
204
+ name: yard
177
205
  requirement: !ruby/object:Gem::Requirement
178
206
  requirements:
179
207
  - - "~>"
180
208
  - !ruby/object:Gem::Version
181
- version: '0.10'
209
+ version: '0.8'
182
210
  type: :development
183
211
  prerelease: false
184
212
  version_requirements: !ruby/object:Gem::Requirement
185
213
  requirements:
186
214
  - - "~>"
187
215
  - !ruby/object:Gem::Version
188
- version: '0.10'
216
+ version: '0.8'
189
217
  description: Sensu plugins for docker
190
218
  email: "<sensu-users@googlegroups.com>"
191
219
  executables:
220
+ - metrics-docker-stats.rb
192
221
  - metrics-docker-container.rb
193
222
  - check-docker-container.rb
194
223
  - check-container.rb
@@ -201,6 +230,7 @@ files:
201
230
  - bin/check-container.rb
202
231
  - bin/check-docker-container.rb
203
232
  - bin/metrics-docker-container.rb
233
+ - bin/metrics-docker-stats.rb
204
234
  - lib/sensu-plugins-docker.rb
205
235
  - lib/sensu-plugins-docker/version.rb
206
236
  homepage: https://github.com/sensu-plugins/sensu-plugins-docker
@@ -229,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
259
  version: '0'
230
260
  requirements: []
231
261
  rubyforge_project:
232
- rubygems_version: 2.4.6
262
+ rubygems_version: 2.4.8
233
263
  signing_key:
234
264
  specification_version: 4
235
265
  summary: Sensu plugins for docker
metadata.gz.sig CHANGED
@@ -1,2 +1,4 @@
1
- 4f5yD�
2
- G���sxհ���I�6mܒމ��A@c��:X��y�`A��C������య�/��(��k�>0���5,G�������TlR���W����>�O�|�:L.�6!2,*Vvnk.4U= KW�z��d��<�ɲS��I鋌�Mc U��_���з�>I
1
+ T�����+ʿc��L)Rk��}��8
2
+ �����z岢� �����#�<ok9q7iPqT^�^��[Sg|�� x�J��Y�,
3
+ �N�ے˲��m�)���@��bz�&R����{�sJ�ʰ��W�
4
+ G�oD�pA��M�z�[۾� I�n$"[b�(6�4�]O��:��G�ɚ*N����"߁6��-,