Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions bin/metrics-docker-stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sensu-plugins-docker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down