Add docker plugin#4191
Conversation
| # only one of them will run (they have the same name) | ||
| # | ||
| local: | ||
| url: 'unix://var/run/docker.sock' |
There was a problem hiding this comment.
I think we can have another one for the case netdata runs in a container itself:
local:
url: 'unix://host/var/run/docker.sock'
So both at the same time. Only one will work.
There was a problem hiding this comment.
Hmmm I don't understand, a 2nd
local:
url: 'unix://host/var/run/docker.sock'
?
There was a problem hiding this comment.
I also don't understand that. @ktsaou what do you mean? Containerized netdata shouldn't have unix://host/var/run/docker.sock socket, it is mounted as unix://var/run/docker.sock
As per: https://github.com/firehol/netdata/wiki/Install-netdata-with-Docker#run-netdata-with-docker-command
There was a problem hiding this comment.
ok,
python plugin supports jobs. When 2 jobs have the same name, the code picks the first that works.
We use this feature for auto-detection. Let's assume nginx files on ubuntu are on /var/log/www and on centos on /var/log/httpd. We create 2 jobs with the same name, and the plugin will pick the first job that works. The same is true for example when we try to connect to a port. We try localhost, 127.0.0.1 and ::1 - only one will actually be used - the first that succeeds will obsolete the others.
Though the instructions I gave you above are wrong. The right config is:
local_run:
name: 'local'
url: 'unix://var/run/docker.sock'
local_host:
name: 'local'
url: 'unix://host/var/run/docker.sock'
So, the first of the above that will succeed, will obsolete the other. Only one job for each name is used.
There was a problem hiding this comment.
And now I saw that containerized netdata has the socket as /var/run/docker.sock, so the above are not needed.
Sorry...
python.d/dockerd.chart.py
Outdated
| import docker | ||
| DOCKER_PY = True | ||
| except ImportError: | ||
| DOCKER_PY = False |
python.d/dockerd.chart.py
Outdated
|
|
||
| self.client = docker.DockerClient(base_url=self.configuration.get('url', 'unix://var/run/docker.sock')) | ||
|
|
||
| return True if self.client else False |
There was a problem hiding this comment.
self.client is always True. It is just initialization.
| data['healthy_containers'] = len(self.client.containers.list(filters={'health': 'healthy'})) | ||
| data['unhealthy_containers'] = len(self.client.containers.list(filters={'health': 'unhealthy'})) | ||
|
|
||
| return data or None |
There was a problem hiding this comment.
self.client.containers.list() returns a list of Containers objects. Does object provide method/attribute about health status?
If so we can call self.client.containers.list() only once then.
There was a problem hiding this comment.
It doesn't seems possible, we have to call it multiple times https://docker-py.readthedocs.io/en/stable/containers.html
There was a problem hiding this comment.
Ok, i see list method has sparse option
sparse (bool) – Do not inspect containers. Returns partial information, but guaranteed not to block
Can we use it together with health filter?
There was a problem hiding this comment.
Oh yes we can do that, I'm adding it
|
|
||
| self.client = docker.DockerClient(base_url=self.configuration.get('url', 'unix://var/run/docker.sock')) | ||
|
|
||
| return True |
There was a problem hiding this comment.
check checks only if python docker package is installed.
We need to check if we can to connect and retrieve data.
There was a problem hiding this comment.
I can do a docker.version() with a try to see if it's ok for more safety
There was a problem hiding this comment.
I used docker.ping() instead https://docker-py.readthedocs.io/en/stable/client.html#docker.client.DockerClient.ping
|
@ktsaou while we are on the subject of monitoring healthy containers, does netdata have HTTP endpoint for healthchecks? |
You mean to check remote http endpoints for their health (it has The later does not exist yet. Do you have something in mind? You know something similar? |
|
I mean, do netdata by itself have some endpoint which could be checked if it finished bootstraping process (is healthy)? Something that would show that netdata finished initial I don't mean to check health status of other services. It doesn't need to be HTTP endpoint, just something that can be easily checked in automated fashion (not by parsing logs). This would allow us to use |
| **Requirement:** | ||
| * `docker` package | ||
|
|
||
| ### configuration |
|
so, merge? |
|
yes |
As discussed in #4111, I have created a plugin to allow us to have some docker metrics.
For now only running containers, healthy and unhealthy container with an alarm when unhealthy containers > 0