Skip to content

Add docker plugin#4191

Merged
ktsaou merged 1 commit intonetdata:masterfrom
MilleniumStudio:docker
Sep 17, 2018
Merged

Add docker plugin#4191
ktsaou merged 1 commit intonetdata:masterfrom
MilleniumStudio:docker

Conversation

@tuxity
Copy link
Contributor

@tuxity tuxity commented Sep 13, 2018

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

# only one of them will run (they have the same name)
#
local:
url: 'unix://var/run/docker.sock'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@tuxity tuxity Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I don't understand, a 2nd

local:
    url: 'unix://host/var/run/docker.sock'

?

Copy link
Contributor

@paulfantom paulfantom Sep 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now I saw that containerized netdata has the socket as /var/run/docker.sock, so the above are not needed.
Sorry...

@ktsaou ktsaou requested a review from ilyam8 September 13, 2018 21:09
import docker
DOCKER_PY = True
except ImportError:
DOCKER_PY = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name it HAS_DOCKER


self.client = docker.DockerClient(base_url=self.configuration.get('url', 'unix://var/run/docker.sock'))

return True if self.client else False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seems possible, we have to call it multiple times https://docker-py.readthedocs.io/en/stable/containers.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check checks only if python docker package is installed.

We need to check if we can to connect and retrieve data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do a docker.version() with a try to see if it's ok for more safety

Copy link
Contributor Author

@tuxity tuxity Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulfantom
Copy link
Contributor

@ktsaou while we are on the subject of monitoring healthy containers, does netdata have HTTP endpoint for healthchecks?

@ktsaou
Copy link
Member

ktsaou commented Sep 14, 2018

@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 http_check plugin), or receive traps of some kind from remote apps?

The later does not exist yet. Do you have something in mind? You know something similar?

@paulfantom
Copy link
Contributor

paulfantom commented Sep 15, 2018

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 discovery stage and it is ready to collect metrics (fully operational).

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 HEALTHCHECK directive in Dockerfile

**Requirement:**
* `docker` package

### configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add plugin charts info

@ktsaou
Copy link
Member

ktsaou commented Sep 16, 2018

so, merge?

@ilyam8
Copy link
Member

ilyam8 commented Sep 17, 2018

yes

@ktsaou ktsaou merged commit b3578ca into netdata:master Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants