@cryptotaxi247 / netdata-1 / commits / b3578ca63

Add docker plugin (#4191)

Kévin Darcel committed Sep 17, 2018 at 17:59 UTC b3578ca63a0ac375cc8ba30923577605ecce53dd
6 files changed +202 -8
conf.d/Makefile.am
+2
@@ -37,6 +37,7 @@ dist_pythonconfig_DATA = \
37 python.d/cpufreq.conf \
38 python.d/dns_query_time.conf \
39 python.d/dnsdist.conf \
40 + python.d/dockerd.conf \
41 python.d/dovecot.conf \
42 python.d/elasticsearch.conf \
43 python.d/example.conf \
@@ -102,6 +103,7 @@ dist_healthconfig_DATA = \
103 health.d/cpu.conf \
104 health.d/couchdb.conf \
105 health.d/disks.conf \
106 + health.d/dockerd.conf \
107 health.d/elasticsearch.conf \
108 health.d/entropy.conf \
109 health.d/fping.conf \
conf.d/health.d/dockerd.conf new
+8
@@ -0,0 +1,8 @@
1 +template: docker_unhealthy_containers
2 + on: docker.unhealthy_containers
3 + units: unhealthy containers
4 + every: 10s
5 + lookup: average -10s
6 + crit: $this > 0
7 + info: number of unhealthy containers
8 + to: sysadmin
conf.d/python.d/dockerd.conf new
+79
@@ -0,0 +1,79 @@
1 +# netdata python.d.plugin configuration for dockerd health data API
2 +#
3 +# This file is in YaML format. Generally the format is:
4 +#
5 +# name: value
6 +#
7 +# There are 2 sections:
8 +# - global variables
9 +# - one or more JOBS
10 +#
11 +# JOBS allow you to collect values from multiple sources.
12 +# Each source will have its own set of charts.
13 +#
14 +# JOB parameters have to be indented (using spaces only, example below).
15 +
16 +# ----------------------------------------------------------------------
17 +# Global Variables
18 +# These variables set the defaults for all JOBs, however each JOB
19 +# may define its own, overriding the defaults.
20 +
21 +# update_every sets the default data collection frequency.
22 +# If unset, the python.d.plugin default is used.
23 +# update_every: 1
24 +
25 +# priority controls the order of charts at the netdata dashboard.
26 +# Lower numbers move the charts towards the top of the page.
27 +# If unset, the default for python.d.plugin is used.
28 +# priority: 60000
29 +
30 +# retries sets the number of retries to be made in case of failures.
31 +# If unset, the default for python.d.plugin is used.
32 +# Attempts to restore the service are made once every update_every
33 +# and only if the module has collected values in the past.
34 +# retries: 60
35 +
36 +# autodetection_retry sets the job re-check interval in seconds.
37 +# The job is not deleted if check fails.
38 +# Attempts to start the job are made once every autodetection_retry.
39 +# This feature is disabled by default.
40 +# autodetection_retry: 0
41 +
42 +# ----------------------------------------------------------------------
43 +# JOBS (data collection sources)
44 +#
45 +# The default JOBS share the same *name*. JOBS with the same name
46 +# are mutually exclusive. Only one of them will be allowed running at
47 +# any time. This allows autodetection to try several alternatives and
48 +# pick the one that works.
49 +#
50 +# Any number of jobs is supported.
51 +#
52 +# All python.d.plugin JOBS (for all its modules) support a set of
53 +# predefined parameters. These are:
54 +#
55 +# job_name:
56 +# name: myname # the JOB's name as it will appear at the
57 +# # dashboard (by default is the job_name)
58 +# # JOBs sharing a name are mutually exclusive
59 +# update_every: 1 # the JOB's data collection frequency
60 +# priority: 60000 # the JOB's order on the dashboard
61 +# retries: 10 # the JOB's number of restoration attempts
62 +# autodetection_retry: 0 # the JOB's re-check interval in seconds
63 +#
64 +# Additionally to the above, dockerd plugin also supports the following:
65 +#
66 +# url: '<scheme>://<host>:<port>/<health_page_api>'
67 +# # http://localhost:8080/health
68 +#
69 +# if the URL is password protected, the following are supported:
70 +#
71 +# user: 'username'
72 +# pass: 'password'
73 +#
74 +# ----------------------------------------------------------------------
75 +# AUTO-DETECTION JOBS
76 +# only one of them will run (they have the same name)
77 +#
78 +local:
79 + url: 'unix://var/run/docker.sock'
python.d/Makefile.am
+1
@@ -23,6 +23,7 @@ dist_python_DATA = \
23 cpuidle.chart.py \
24 dns_query_time.chart.py \
25 dnsdist.chart.py \
26 + dockerd.chart.py \
27 dovecot.chart.py \
28 elasticsearch.chart.py \
29 example.chart.py \
python.d/README.md
+37 -8
@@ -526,6 +526,35 @@ localhost:
526 X-API-Key: 'dnsdist-api-key'
527 ```
528
529 +---
530 +
531 +# docker
532 +
533 +Module monitor docker health metrics.
534 +
535 +**Requirement:**
536 +* `docker` package
537 +
538 +Following charts are drawn:
539 +
540 +1. **running containers**
541 + * count
542 +
543 +2. **healthy containers**
544 + * count
545 +
546 +3. **unhealthy containers**
547 + * count
548 +
549 +### configuration
550 +
551 +```yaml
552 + update_every : 1
553 + priority : 60000
554 + ```
555 +
556 +---
557 +
558 # dovecot
559
560 This module provides statistics information from dovecot server.
@@ -1037,15 +1066,15 @@ It produces:
1066
1067 6. **Requests In Processing** in requests
1068 * processing
1040 -
1069 +
1070 7. **Public Cache Hits** in hits/s
1071 * hits
1043 -
1072 +
1073 8. **Private Cache Hits** in hits/s
1074 * hits
1046 -
1075 +
1076 9. **Static Hits** in hits/s
1048 - * hits
1077 + * hits
1078
1079
1080 ### configuration
@@ -1150,8 +1179,8 @@ Module collects adapter, physical drives and battery stats.
1179 To grab stats it executes:
1180 * `sudo -n megacli -LDPDInfo -aAll`
1181 * `sudo -n megacli -AdpBbuCmd -a0`
1153 -
1154 -
1182 +
1183 +
1184 It produces:
1185
1186 1. **Adapter State**
@@ -2026,9 +2055,9 @@ Powerdns charts:
2055
2056 4. **Latency**
2057 * latency
2029 -
2058 +
2059 Powerdns Recursor charts:
2031 -
2060 +
2061 1. **Questions In**
2062 * questions
2063 * ipv6-questions
python.d/dockerd.chart.py new
+75
@@ -0,0 +1,75 @@
1 +# -*- coding: utf-8 -*-
2 +# Description: docker netdata python.d module
3 +# Author: Kévin Darcel (@tuxity)
4 +
5 +try:
6 + import docker
7 + HAS_DOCKER = True
8 +except ImportError:
9 + HAS_DOCKER = False
10 +
11 +from bases.FrameworkServices.SimpleService import SimpleService
12 +
13 +# default module values (can be overridden per job in `config`)
14 +# update_every = 1
15 +priority = 60000
16 +retries = 60
17 +
18 +# charts order (can be overridden if you want less charts, or different order)
19 +ORDER = [
20 + 'running_containers',
21 + 'healthy_containers',
22 + 'unhealthy_containers'
23 +]
24 +
25 +CHARTS = {
26 + 'running_containers': {
27 + 'options': [None, 'Number of running containers', 'running containers', 'running containers', 'docker.running_containers', 'line'],
28 + 'lines': [
29 + ['running_containers', 'running']
30 + ]
31 + },
32 + 'healthy_containers': {
33 + 'options': [None, 'Number of healthy containers', 'healthy containers', 'healthy containers', 'docker.healthy_containers', 'line'],
34 + 'lines': [
35 + ['healthy_containers', 'healthy']
36 + ]
37 + },
38 + 'unhealthy_containers': {
39 + 'options': [None, 'Number of unhealthy containers', 'unhealthy containers', 'unhealthy containers', 'docker.unhealthy_containers', 'line'],
40 + 'lines': [
41 + ['unhealthy_containers', 'unhealthy']
42 + ]
43 + }
44 +}
45 +
46 +
47 +class Service(SimpleService):
48 + def __init__(self, configuration=None, name=None):
49 + SimpleService.__init__(self, configuration=configuration, name=name)
50 + self.order = ORDER
51 + self.definitions = CHARTS
52 +
53 + def check(self):
54 + if not HAS_DOCKER:
55 + self.error('\'docker\' package is needed to use docker.chart.py')
56 + return False
57 +
58 + self.client = docker.DockerClient(base_url=self.configuration.get('url', 'unix://var/run/docker.sock'))
59 +
60 + try:
61 + self.client.ping()
62 + except docker.errors.APIError as error:
63 + self.error(error)
64 + return False
65 +
66 + return True
67 +
68 + def get_data(self):
69 + data = dict()
70 + data['running_containers'] = len(self.client.containers.list(sparse=True))
71 + data['healthy_containers'] = len(self.client.containers.list(filters={'health': 'healthy'}, sparse=True))
72 + data['unhealthy_containers'] = len(self.client.containers.list(filters={'health': 'unhealthy'}, sparse=True))
73 +
74 + return data or None
75 +