Révision 9e2b9182
Added env to exclude containers from cpu/memory docker graphs
It maybe desirable to not generate stats for ephemeral containers.
This commit adds an env variable EXCLUDE_CONTAINER_NAME which is a regex, if it matches
then the container is excluded from the cpu and memory graphs.
| plugins/docker/docker_ | ||
|---|---|---|
| 38 | 38 |
Docker environment variables here as described in |
| 39 | 39 |
https://docs.docker.com/compose/reference/envvars/): |
| 40 | 40 |
|
| 41 |
You can use the EXCLUDE_CONTAINER_NAME environment variable to specify a regular expression |
|
| 42 |
which if matched will exclude the matching containers from the memory and cpu graphs. |
|
| 43 |
|
|
| 44 |
For example |
|
| 45 |
|
|
| 46 |
env.EXCLUDE_CONTAINER_NAME runner |
|
| 47 |
|
|
| 48 |
Would exclude all containers with the word "runner" in the name. |
|
| 49 |
|
|
| 50 |
|
|
| 41 | 51 |
=over 2 |
| 42 | 52 |
|
| 43 | 53 |
[docker_*] |
| 44 | 54 |
user root |
| 45 | 55 |
env.DOCKER_HOST unix://var/run/docker.sock |
| 56 |
env.EXCLUDE_CONTAINER_NAME regexp |
|
| 46 | 57 |
|
| 47 | 58 |
=back |
| 48 | 59 |
""" |
| ... | ... | |
| 50 | 61 |
import os |
| 51 | 62 |
import sys |
| 52 | 63 |
import docker |
| 64 |
import re |
|
| 53 | 65 |
from multiprocessing import Process, Queue |
| 54 | 66 |
|
| 55 | 67 |
|
| ... | ... | |
| 92 | 104 |
def parallel_container_stats(client): |
| 93 | 105 |
proc_list = [] |
| 94 | 106 |
stats = {}
|
| 107 |
exclude = os.getenv('EXCLUDE_CONTAINER_NAME')
|
|
| 95 | 108 |
for container in client.containers.list(): |
| 109 |
if exclude and re.search(exclude, container.name): |
|
| 110 |
break |
|
| 96 | 111 |
q = Queue() |
| 97 | 112 |
p = Process(target=get_container_stats, args=(container, q)) |
| 98 | 113 |
proc_list.append({'proc': p, 'queue': q, 'container': container})
|
Formats disponibles : Unified diff