summaryrefslogtreecommitdiffstats
path: root/collectors/python.d.plugin/dockerd/dockerd.chart.py
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/python.d.plugin/dockerd/dockerd.chart.py')
-rw-r--r--collectors/python.d.plugin/dockerd/dockerd.chart.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/collectors/python.d.plugin/dockerd/dockerd.chart.py b/collectors/python.d.plugin/dockerd/dockerd.chart.py
index a0d3d7e65..8bd45df9e 100644
--- a/collectors/python.d.plugin/dockerd/dockerd.chart.py
+++ b/collectors/python.d.plugin/dockerd/dockerd.chart.py
@@ -10,10 +10,8 @@ except ImportError:
from bases.FrameworkServices.SimpleService import SimpleService
-# default module values (can be overridden per job in `config`)
-# update_every = 1
-priority = 60000
-retries = 60
+from distutils.version import StrictVersion
+
# charts order (can be overridden if you want less charts, or different order)
ORDER = [
@@ -24,21 +22,21 @@ ORDER = [
CHARTS = {
'running_containers': {
- 'options': [None, 'Number of running containers', 'running containers', 'running containers',
+ 'options': [None, 'Number of running containers', 'containers', 'running containers',
'docker.running_containers', 'line'],
'lines': [
['running_containers', 'running']
]
},
'healthy_containers': {
- 'options': [None, 'Number of healthy containers', 'healthy containers', 'healthy containers',
+ 'options': [None, 'Number of healthy containers', 'containers', 'healthy containers',
'docker.healthy_containers', 'line'],
'lines': [
['healthy_containers', 'healthy']
]
},
'unhealthy_containers': {
- 'options': [None, 'Number of unhealthy containers', 'unhealthy containers', 'unhealthy containers',
+ 'options': [None, 'Number of unhealthy containers', 'containers', 'unhealthy containers',
'docker.unhealthy_containers', 'line'],
'lines': [
['unhealthy_containers', 'unhealthy']
@@ -47,15 +45,26 @@ CHARTS = {
}
+MIN_REQUIRED_VERSION = '3.2.0'
+
+
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
+ self.client = None
def check(self):
if not HAS_DOCKER:
- self.error('\'docker\' package is needed to use docker.chart.py')
+ self.error("'docker' package is needed to use dockerd module")
+ return False
+
+ if StrictVersion(docker.__version__) < StrictVersion(MIN_REQUIRED_VERSION):
+ self.error("installed 'docker' package version {0}, minimum required version {1}, please upgrade".format(
+ docker.__version__,
+ MIN_REQUIRED_VERSION,
+ ))
return False
self.client = docker.DockerClient(base_url=self.configuration.get('url', 'unix://var/run/docker.sock'))
@@ -70,6 +79,7 @@ class Service(SimpleService):
def get_data(self):
data = dict()
+
data['running_containers'] = len(self.client.containers.list(sparse=True))
data['healthy_containers'] = len(self.client.containers.list(filters={'health': 'healthy'}, sparse=True))
data['unhealthy_containers'] = len(self.client.containers.list(filters={'health': 'unhealthy'}, sparse=True))