diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb3c86..d06e77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) ## [Unreleased] +### Added + - metrics-docker-stats.rb: New option `--container-list-regex` to filter containers using Regex String (@parin921996). + ## [3.1.1] - 2018 ### Fixed - check-container-logs.rb: fix nil.gsub condition on empty log lines diff --git a/bin/metrics-docker-stats.rb b/bin/metrics-docker-stats.rb index 0c58a01..5c4785e 100755 --- a/bin/metrics-docker-stats.rb +++ b/bin/metrics-docker-stats.rb @@ -66,6 +66,11 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite long: '--container-name CONTAINER', default: '' + option :container_list_regex, + description: 'Regex for container list to collect metrics for', + short: '-R CONTAINER_LIST_REGEX', + long: '--container-list-regex CONTAINER_LIST_REGEX' + option :docker_host, description: 'Docker API URI. https://host, https://host:port, http://host, http://host:port, host:port, unix:///path', short: '-H DOCKER_HOST', @@ -109,12 +114,24 @@ class DockerStatsMetrics < Sensu::Plugin::Metric::CLI::Graphite boolean: true, default: false + def create_container_list(container_list, pattern) + matched_list = [] + container_list.each do |container| + if container =~ /#{pattern}/ + matched_list.push(container) + end + end + matched_list + end + def run @timestamp = Time.now.to_i @client = DockerApi.new(config[:docker_host]) list = if config[:container] != '' [config[:container]] + elsif !config[:container_list_regex].nil? + create_container_list(list_containers, config[:container_list_regex]) else list_containers end diff --git a/sensu-plugins-docker.gemspec b/sensu-plugins-docker.gemspec index 4f1c338..64dc909 100644 --- a/sensu-plugins-docker.gemspec +++ b/sensu-plugins-docker.gemspec @@ -38,6 +38,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4' s.add_development_dependency 'github-markup', '~> 1.3' s.add_development_dependency 'kitchen-docker', '~> 2.6' + # TODO: remove this pin when we remove ruby 2.3 support, see: https://github.com/ruby/net-telnet/issues/14 for more information + s.add_development_dependency 'net-telnet', '0.1.1' s.add_development_dependency 'pry', '~> 0.10' s.add_development_dependency 'rake', '~> 10.0' s.add_development_dependency 'redcarpet', '~> 3.2'