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 #25 from signalfx/new-docker-client
Browse files Browse the repository at this point in the history
Using New Docker Client Python Package
  • Loading branch information
mpetazzoni authored Sep 6, 2017
2 parents 9d08a56 + 69153ec commit 9f44322
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@

This file documents important changes to the Docker plugin for collectd.

- [2017-09-06: Use New Docker Python Client](#2017-09-06)
- [2017-03-31: Update Documentation For Filtering Blkio Metrics](#2017-03-31)
- [2017-03-29: Improve Dimension Extraction Robustness](#2017-03-29)
- [2016-08-03: Dimensionalize block I/O and CPU per-core metrics](#2016-08-03)

#### <a name="2017-09-06">2017-09-06: Use New Docker Python Client</a>

The old `docker-py` pip package has been deprecated, so we are switching to the
new `docker` pip package. This means that the oldest version of docker we can
support is 1.21.

The only change to metric output is that now all network datapoints have an
`interface` dimension and there can potentially be multiple interfaces per
container.

If you are updating an existing collectd installation, you will need to
manually uninstall docker-py by running `pip uninstall docker-py` and then
reinstall the `requirements.txt` file from this repo.

#### <a name="2017-03-31">2017-03-31: Update Documentation For Filtering Blkio Metrics</a>

Update documentation for filtering blkio Metrics.
Expand Down
15 changes: 9 additions & 6 deletions dockerplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,14 @@ def read_cpu_stats(container, dimensions, stats, t):

def read_network_stats(container, dimensions, stats, t):
"""Process network utilization stats for a container."""
net_stats = stats['network']
net_stats = stats['networks']
log.info('Reading network stats: {0}'.format(net_stats))

items = sorted(net_stats.items())
emit(container, dimensions, 'network.usage', [x[1] for x in items], t=t)
for interface, if_stats in net_stats.items():
items = sorted(if_stats.items())
interface_dims = dimensions.copy()
interface_dims['interface'] = interface
emit(container, interface_dims, 'network.usage', [x[1] for x in items], t=t)


def read_memory_stats(container, dimensions, stats, t):
Expand Down Expand Up @@ -388,8 +391,8 @@ class DockerPlugin:
DEFAULT_BASE_URL = 'unix://var/run/docker.sock'
DEFAULT_DOCKER_TIMEOUT = 5

# The stats endpoint is only supported by API >= 1.17
MIN_DOCKER_API_VERSION = '1.17'
# The new docker package only supports 1.21+.
MIN_DOCKER_API_VERSION = '1.21'
MIN_DOCKER_API_STRICT_VERSION = StrictVersion(MIN_DOCKER_API_VERSION)

# TODO: add support for 'networks' from API >= 1.20 to get by-iface stats.
Expand Down Expand Up @@ -537,7 +540,7 @@ def configure_callback(self, conf):
self.dimensions = DimensionsProvider(specs)

def init_callback(self):
self.client = docker.Client(
self.client = docker.APIClient(
base_url=self.docker_url,
version=DockerPlugin.MIN_DOCKER_API_VERSION)
self.client.timeout = self.timeout
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
py-dateutil
docker-py>=1.0.0
docker
jsonpath_rw

0 comments on commit 9f44322

Please sign in to comment.