sensu-plugins-docker 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/README.md +1 -0
- data/bin/metrics-docker-info.rb +91 -0
- data/bin/metrics-docker-stats.rb +43 -2
- data/lib/sensu-plugins-docker/version.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a0c669db204f3d8f22810459efda23ae2deb92e
|
4
|
+
data.tar.gz: cc6319e61a7c19d261ab14a3c368173b6a428f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8290f04f055c64d86316f0cb2a1739a26ef1b078b0384a53fae609d96aa6f93d82ab412ab1f3549d4cca7089db9ce1423d26e78bd26d9ec2261ea04a74d522a
|
7
|
+
data.tar.gz: 28d541dee490616f29e48ff003aac8c77e2b849a8a3c75d7a3f21e10fd642b488e9e570c786934ce2a422cc0312d6cddeff6350adab4dca31d55c83896fbbc3c
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
-
#Change Log
|
1
|
+
# Change Log
|
2
2
|
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
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [1.4.0] - 2017-08-08
|
9
|
+
### Added
|
10
|
+
- metrics-docker-info.rb: general information metrics from docker (@alcasim)
|
11
|
+
- metrics-docker-stats.rb: Added to include environment variables values as part of the metric. Added I/O stats option (@alcasim)
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Ruby 2.4.1 testing
|
15
|
+
|
8
16
|
## [1.3.1] - 2017-06-12
|
9
17
|
### Fixed
|
10
18
|
- check-container.rb: fixes to work with docker >= 1.17 (@israelriibeiro)
|
@@ -88,7 +96,8 @@ changes some options. Review your check commands before deploying this version.
|
|
88
96
|
### Added
|
89
97
|
- initial release
|
90
98
|
|
91
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.
|
99
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.4.0...HEAD
|
100
|
+
[1.4.0]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.3.1...1.4.0
|
92
101
|
[1.3.1]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.3.0...1.3.1
|
93
102
|
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.2.0...1.3.0
|
94
103
|
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-docker/compare/1.1.5...1.2.0
|
data/README.md
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-docker-info
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# This check gather certain general stats from Docker (number of CPUs, number of containers, images...)
|
8
|
+
# Supports the stats feature of the docker remote api ( docker server 1.5 and newer )
|
9
|
+
# Supports connecting to docker remote API over Unix socket or TCP
|
10
|
+
# Based on metrics-docker-stats by @paulczar
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# OUTPUT:
|
14
|
+
# metric-data
|
15
|
+
#
|
16
|
+
# PLATFORMS:
|
17
|
+
# Linux
|
18
|
+
#
|
19
|
+
# DEPENDENCIES:
|
20
|
+
# gem: sensu-plugin
|
21
|
+
#
|
22
|
+
# USAGE:
|
23
|
+
# Gather stats using unix socket:
|
24
|
+
# metrics-docker-info.rb -p unix -H /var/run/docker.sock
|
25
|
+
#
|
26
|
+
# Gather stats from localhost using TCP:
|
27
|
+
# metrics-docker-info.rb -p http -H localhost:2375
|
28
|
+
#
|
29
|
+
# See metrics-docker-info.rb --help for full usage flags
|
30
|
+
#
|
31
|
+
# NOTES:
|
32
|
+
#
|
33
|
+
# LICENSE:
|
34
|
+
# Copyright 2017 Alfonso Casimiro. Github @alcasim
|
35
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
36
|
+
# for details.
|
37
|
+
#
|
38
|
+
|
39
|
+
require 'sensu-plugin/metric/cli'
|
40
|
+
require 'socket'
|
41
|
+
require 'net_http_unix'
|
42
|
+
require 'json'
|
43
|
+
|
44
|
+
class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
45
|
+
option :scheme,
|
46
|
+
description: 'Metric naming scheme, text to prepend to metric',
|
47
|
+
short: '-s SCHEME',
|
48
|
+
long: '--scheme SCHEME',
|
49
|
+
default: "#{Socket.gethostname}.docker"
|
50
|
+
|
51
|
+
option :docker_host,
|
52
|
+
description: 'Docker socket to connect. TCP: "host:port" or Unix: "/path/to/docker.sock" (default: "127.0.0.1:2375")',
|
53
|
+
short: '-H DOCKER_HOST',
|
54
|
+
long: '--docker-host DOCKER_HOST',
|
55
|
+
default: '/var/run/docker.sock'
|
56
|
+
|
57
|
+
option :docker_protocol,
|
58
|
+
description: 'http or unix',
|
59
|
+
short: '-p PROTOCOL',
|
60
|
+
long: '--protocol PROTOCOL',
|
61
|
+
default: 'unix'
|
62
|
+
|
63
|
+
def run
|
64
|
+
@timestamp = Time.now.to_i
|
65
|
+
path = 'info'
|
66
|
+
infolist = docker_api(path)
|
67
|
+
filtered_list = infolist.select { |key, _value| key.match(/NCPU|NFd|Containers|Images|NGoroutines|NEventsListener|MemTotal/) }
|
68
|
+
filtered_list.each do |key, value|
|
69
|
+
output "#{config[:scheme]}.#{key}", value, @timestamp
|
70
|
+
end
|
71
|
+
ok
|
72
|
+
end
|
73
|
+
|
74
|
+
def docker_api(path)
|
75
|
+
if config[:docker_protocol] == 'unix'
|
76
|
+
session = NetX::HTTPUnix.new("unix://#{config[:docker_host]}")
|
77
|
+
request = Net::HTTP::Get.new "/#{path}"
|
78
|
+
else
|
79
|
+
uri = URI("#{config[:docker_protocol]}://#{config[:docker_host]}/#{path}")
|
80
|
+
session = Net::HTTP.new(uri.host, uri.port)
|
81
|
+
request = Net::HTTP::Get.new uri.request_uri
|
82
|
+
end
|
83
|
+
|
84
|
+
session.start do |http|
|
85
|
+
http.request request do |response|
|
86
|
+
response.value
|
87
|
+
return JSON.parse(response.read_body)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/bin/metrics-docker-stats.rb
CHANGED
@@ -99,6 +99,18 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
99
99
|
long: '--deliminator',
|
100
100
|
default: '-'
|
101
101
|
|
102
|
+
option :environment_tags,
|
103
|
+
description: 'Name of environment variables on each container to be appended to metric name, separated by commas',
|
104
|
+
short: '-e ENVIRONMENT_VARIABLES',
|
105
|
+
long: '--environment-tags ENVIRONMENT_VARIABLES'
|
106
|
+
|
107
|
+
option :ioinfo,
|
108
|
+
description: 'enable IO Docker metrics',
|
109
|
+
short: '-i',
|
110
|
+
long: '--ioinfo',
|
111
|
+
boolean: true,
|
112
|
+
default: false
|
113
|
+
|
102
114
|
def run
|
103
115
|
@timestamp = Time.now.to_i
|
104
116
|
|
@@ -109,14 +121,17 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
109
121
|
end
|
110
122
|
list.each do |container|
|
111
123
|
stats = container_stats(container)
|
124
|
+
scheme = ''
|
125
|
+
unless config[:environment_tags].nil?
|
126
|
+
scheme << container_tags(container)
|
127
|
+
end
|
112
128
|
if config[:name_parts]
|
113
|
-
scheme = ''
|
114
129
|
config[:name_parts].split(',').each do |key|
|
115
130
|
scheme << '.' unless scheme == ''
|
116
131
|
scheme << container.split(config[:delim])[key.to_i]
|
117
132
|
end
|
118
133
|
else
|
119
|
-
scheme
|
134
|
+
scheme << container
|
120
135
|
end
|
121
136
|
output_stats(scheme, stats)
|
122
137
|
end
|
@@ -130,6 +145,11 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
130
145
|
next if value.is_a?(Array)
|
131
146
|
output "#{config[:scheme]}.#{container}.#{key}", value, @timestamp
|
132
147
|
end
|
148
|
+
if config[:ioinfo]
|
149
|
+
blkio_stats(stats['blkio_stats']).each do |key, value|
|
150
|
+
output "#{config[:scheme]}.#{container}.#{key}", value, @timestamp
|
151
|
+
end
|
152
|
+
end
|
133
153
|
end
|
134
154
|
|
135
155
|
def docker_api(path)
|
@@ -171,4 +191,25 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite
|
|
171
191
|
path = "containers/#{container}/stats?stream=0"
|
172
192
|
@stats = docker_api(path)
|
173
193
|
end
|
194
|
+
|
195
|
+
def container_tags(container)
|
196
|
+
tags = ''
|
197
|
+
path = "containers/#{container}/json"
|
198
|
+
@inspect = docker_api(path)
|
199
|
+
tag_list = config[:environment_tags].split(',')
|
200
|
+
tag_list.each do |value|
|
201
|
+
tags << @inspect['Config']['Env'].select { |tag| tag.to_s.match(/#{value}=/) }.first.gsub(/#{value}=/, '') + '.'
|
202
|
+
end
|
203
|
+
tags
|
204
|
+
end
|
205
|
+
|
206
|
+
def blkio_stats(io_stats)
|
207
|
+
stats_out = {}
|
208
|
+
io_stats.each do |stats_type, stats_vals|
|
209
|
+
stats_vals.each do |value|
|
210
|
+
stats_out["#{stats_type}.#{value['op']}.#{value['major']}.#{value['minor']}"] = value['value']
|
211
|
+
end
|
212
|
+
end
|
213
|
+
stats_out
|
214
|
+
end
|
174
215
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-docker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -201,6 +201,7 @@ email: "<sensu-users@googlegroups.com>"
|
|
201
201
|
executables:
|
202
202
|
- check-container-logs.rb
|
203
203
|
- metrics-docker-container.rb
|
204
|
+
- metrics-docker-info.rb
|
204
205
|
- metrics-docker-stats.rb
|
205
206
|
- check-container.rb
|
206
207
|
- check-docker-container.rb
|
@@ -214,6 +215,7 @@ files:
|
|
214
215
|
- bin/check-container.rb
|
215
216
|
- bin/check-docker-container.rb
|
216
217
|
- bin/metrics-docker-container.rb
|
218
|
+
- bin/metrics-docker-info.rb
|
217
219
|
- bin/metrics-docker-stats.rb
|
218
220
|
- lib/sensu-plugins-docker.rb
|
219
221
|
- lib/sensu-plugins-docker/client_helpers.rb
|