Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]

## [3.1.2] - 2018
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the versioning and dating are left to the maintainers for several reasons:

  • we may disagree on the impact of the change and therefore how its versioned. In this case it would be a minor version bump not a patch as you are adding new functionality. To better understand how we version you can read about it here
  • we date the release rather then when the contribution was submitted, PR review and acceptance has no SLA and is not guaranteed to be merged within the same day
  • PRs are not a FIFO queue, as such versioning them prior to acceptance leads to needing to ask people to rebase more often

### Added
- metrics-docker-stats.rb: New Regex flag to filter container using Regex String.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's include the flag name here --container-list-regex


## [3.1.1] - 2018
### Fixed
- check-container-logs.rb: fix nil.gsub condition on empty log lines
Expand Down
18 changes: 18 additions & 0 deletions bin/metrics-docker-stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ 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',
default: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any benefit of defaulting to an empty string vs just checking when its nil?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check as nil , I will refactor code to usenil.


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 +115,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] != ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can alternatively be expressed as elsif !config[:container_list_regex].empty? but I think it might be best to remove the default empty string and check for !config[:container_list_regex].nil?

create_container_list(list_containers, config[:container_list_regex])
else
list_containers
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-plugins-docker/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SensuPluginsDocker
module Version
MAJOR = 3
MINOR = 1
PATCH = 1
PATCH = 2

VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
end
Expand Down