Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from signalfx/supress-network-config
Browse files Browse the repository at this point in the history
Adding ability to supress network stats
  • Loading branch information
keitwb authored Jan 30, 2018
2 parents b8c9afb + 8300013 commit 894c291
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ LoadPlugin python

The boolean configuration options CpuQuotaPercent and CpuSharesPercent turn on metrics for CPU quota and CPU shares. Both options are set to False by default.

The boolean option `CollectNetworkStats` controls whether container network
stats are collected -- it defaults to true. Some networking backends don't
report network statistics (e.g. when running on Kubernetes) so it can be useful
to disable to avoid error messages.

```apache
TypesDB "/usr/share/collectd/docker-collectd-plugin/dockerplugin.db"
LoadPlugin python
Expand Down
27 changes: 11 additions & 16 deletions dockerplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ def __init__(self, container, dimensions, client):
threading.Thread.__init__(self)
self.daemon = True
self.stop = False
# Indicates whether the container stats has 'networks' information
self.hasNetworks = True
self._container = container
self._client = client
self._feed = None
Expand Down Expand Up @@ -494,6 +492,7 @@ def __init__(self, docker_url=None):
self.stats = {}
self.cpu_quota_bool = False
self.cpu_shares_bool = False
self.collect_network_stats = True

def is_excluded_label(self, container):
"""
Expand Down Expand Up @@ -596,6 +595,8 @@ def configure_callback(self, conf):
self.cpu_quota_bool = str_to_bool(node.values[0])
elif node.key == 'CpuSharesPercent':
self.cpu_shares_bool = str_to_bool(node.values[0])
elif node.key == 'CollectNetworkStats':
self.collect_network_stats = str_to_bool(node.values[0])
elif (node.key == 'ExcludeName' or
node.key == 'ExcludeImage' or
node.key == 'ExcludeLabel'):
Expand Down Expand Up @@ -734,23 +735,17 @@ def read_callback(self):
continue
# Process stats through each reader.
for method in self.METHODS:
if not self.collect_network_stats and method == read_network_stats:
continue
try:
method(container, cstats.dimensions, stats, read_at)
# Reset hasNetworks if networks collects successfully
if method == read_network_stats and \
not cstats.hasNetworks:
cstats.hasNetworks = True
except Exception, e:
if method != read_network_stats or cstats.hasNetworks:
log.exception(('Unable to retrieve {method} stats '
'for container {container}: {msg}')
.format(
method=method.__name__,
container=_c(container),
msg=e
))
if method == read_network_stats and cstats.hasNetworks:
cstats.hasNetworks = False
log.exception(('Unable to retrieve {method} stats '
'for container {container}: {msg}')
.format(
method=method.__name__,
container=_c(container),
msg=e))

# If CPU shares or quota metrics are required
if self.cpu_shares_bool or self.cpu_quota_bool:
Expand Down

0 comments on commit 894c291

Please sign in to comment.