From fb3b733c35fbb03684cd78a0c1461ae65f9e0bba Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Wed, 24 Nov 2021 09:38:52 +0100 Subject: [PATCH] Use Docker-socket-proxy in telegraf configuration --- monitoring/docker-compose.yaml | 5 ++- monitoring/telegraf_host.conf | 76 ---------------------------------- monitoring/telegraf_net.conf | 72 ++++++++++++++++++++++++++++++++ proxy/docker-compose.yaml | 12 ++++-- 4 files changed, 84 insertions(+), 81 deletions(-) mode change 100644 => 100755 proxy/docker-compose.yaml diff --git a/monitoring/docker-compose.yaml b/monitoring/docker-compose.yaml index 7fb6cd5..d8de289 100644 --- a/monitoring/docker-compose.yaml +++ b/monitoring/docker-compose.yaml @@ -109,7 +109,8 @@ services: - ./telegraf_net.conf:/etc/telegraf/telegraf.conf:ro - /var/run/docker.sock:/var/run/docker.sock:ro networks: - - monitoring + - monitoring + - dockersocket labels: - "docker.group=monitoring" depends_on: @@ -121,3 +122,5 @@ networks: external: true web: external: true + dockersocket: + external: true diff --git a/monitoring/telegraf_host.conf b/monitoring/telegraf_host.conf index 43e1e93..4a428a8 100644 --- a/monitoring/telegraf_host.conf +++ b/monitoring/telegraf_host.conf @@ -169,82 +169,6 @@ ## Uncomment to remove deprecated metrics. # fielddrop = ["uptime_format"] - - -# Read metrics about docker containers -[[inputs.docker]] - ## Docker Endpoint - ## To use TCP, set endpoint = "tcp://[ip]:[port]" - ## To use environment variables (ie, docker-machine), set endpoint = "ENV" - endpoint = "unix:///var/run/docker.sock" - - ## Set to true to collect Swarm metrics(desired_replicas, running_replicas) - ## Note: configure this in one of the manager nodes in a Swarm cluster. - ## configuring in multiple Swarm managers results in duplication of metrics. - gather_services = false - - ## Only collect metrics for these containers. Values will be appended to - ## container_name_include. - ## Deprecated (1.4.0), use container_name_include - container_names = [] - - ## Set the source tag for the metrics to the container ID hostname, eg first 12 chars - source_tag = false - - ## Containers to include and exclude. Collect all if empty. Globs accepted. - container_name_include = [] - container_name_exclude = [] - - ## Container states to include and exclude. Globs accepted. - ## When empty only containers in the "running" state will be captured. - ## example: container_state_include = ["created", "restarting", "running", "removing", "paused", "exited", "dead"] - ## example: container_state_exclude = ["created", "restarting", "running", "removing", "paused", "exited", "dead"] - # container_state_include = [] - # container_state_exclude = [] - - ## Timeout for docker list, info, and stats commands - timeout = "5s" - - ## Whether to report for each container per-device blkio (8:0, 8:1...), - ## network (eth0, eth1, ...) and cpu (cpu0, cpu1, ...) stats or not. - ## Usage of this setting is discouraged since it will be deprecated in favor of 'perdevice_include'. - ## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting - ## is honored. - perdevice = false - - ## Specifies for which classes a per-device metric should be issued - ## Possible values are 'cpu' (cpu0, cpu1, ...), 'blkio' (8:0, 8:1, ...) and 'network' (eth0, eth1, ...) - ## Please note that this setting has no effect if 'perdevice' is set to 'true' - perdevice_include = ["cpu", "blkio", "network"] - - ## Whether to report for each container total blkio and network stats or not. - ## Usage of this setting is discouraged since it will be deprecated in favor of 'total_include'. - ## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting - ## is honored. - total = true - - ## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values. - ## Possible values are 'cpu', 'blkio' and 'network' - ## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin. - ## Please note that this setting has no effect if 'total' is set to 'false' - total_include = ["cpu", "blkio", "network"] - - ## docker labels to include and exclude as tags. Globs accepted. - ## Note that an empty array for both will include all labels as tags - docker_label_include = [] - docker_label_exclude = [] - - ## Which environment variables should we use as a tag - tag_env = ["JAVA_HOME", "HEAP_SIZE"] - - ## Optional TLS Config - # tls_ca = "/etc/telegraf/ca.pem" - # tls_cert = "/etc/telegraf/cert.pem" - # tls_key = "/etc/telegraf/key.pem" - ## Use TLS but skip chain & host verification - # insecure_skip_verify = false - - # Gather metrics about network interfaces [[inputs.net]] ## By default, telegraf gathers stats from any up interface (excluding loopback) diff --git a/monitoring/telegraf_net.conf b/monitoring/telegraf_net.conf index 3e068cd..e0394b2 100644 --- a/monitoring/telegraf_net.conf +++ b/monitoring/telegraf_net.conf @@ -102,5 +102,77 @@ data_format = "json" +# Read metrics about docker containers +[[inputs.docker]] + ## Docker Endpoint + ## To use TCP, set endpoint = "tcp://[ip]:[port]" + ## To use environment variables (ie, docker-machine), set endpoint = "ENV" + endpoint = "tcp://docker-socket-proxy:2375" + # endpoint = "unix:///var/run/docker.sock" + ## Set to true to collect Swarm metrics(desired_replicas, running_replicas) + ## Note: configure this in one of the manager nodes in a Swarm cluster. + ## configuring in multiple Swarm managers results in duplication of metrics. + gather_services = false + + ## Only collect metrics for these containers. Values will be appended to + ## container_name_include. + ## Deprecated (1.4.0), use container_name_include + container_names = [] + + ## Set the source tag for the metrics to the container ID hostname, eg first 12 chars + source_tag = false + + ## Containers to include and exclude. Collect all if empty. Globs accepted. + container_name_include = [] + container_name_exclude = [] + + ## Container states to include and exclude. Globs accepted. + ## When empty only containers in the "running" state will be captured. + ## example: container_state_include = ["created", "restarting", "running", "removing", "paused", "exited", "dead"] + ## example: container_state_exclude = ["created", "restarting", "running", "removing", "paused", "exited", "dead"] + # container_state_include = [] + # container_state_exclude = [] + + ## Timeout for docker list, info, and stats commands + timeout = "5s" + + ## Whether to report for each container per-device blkio (8:0, 8:1...), + ## network (eth0, eth1, ...) and cpu (cpu0, cpu1, ...) stats or not. + ## Usage of this setting is discouraged since it will be deprecated in favor of 'perdevice_include'. + ## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting + ## is honored. + perdevice = false + + ## Specifies for which classes a per-device metric should be issued + ## Possible values are 'cpu' (cpu0, cpu1, ...), 'blkio' (8:0, 8:1, ...) and 'network' (eth0, eth1, ...) + ## Please note that this setting has no effect if 'perdevice' is set to 'true' + perdevice_include = ["cpu", "blkio", "network"] + + ## Whether to report for each container total blkio and network stats or not. + ## Usage of this setting is discouraged since it will be deprecated in favor of 'total_include'. + ## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting + ## is honored. + total = true + + ## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values. + ## Possible values are 'cpu', 'blkio' and 'network' + ## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin. + ## Please note that this setting has no effect if 'total' is set to 'false' + total_include = ["cpu", "blkio", "network"] + + ## docker labels to include and exclude as tags. Globs accepted. + ## Note that an empty array for both will include all labels as tags + docker_label_include = [] + docker_label_exclude = [] + + ## Which environment variables should we use as a tag + tag_env = ["JAVA_HOME", "HEAP_SIZE"] + + ## Optional TLS Config + # tls_ca = "/etc/telegraf/ca.pem" + # tls_cert = "/etc/telegraf/cert.pem" + # tls_key = "/etc/telegraf/key.pem" + ## Use TLS but skip chain & host verification + # insecure_skip_verify = false diff --git a/proxy/docker-compose.yaml b/proxy/docker-compose.yaml old mode 100644 new mode 100755 index d5d5d7f..4972766 --- a/proxy/docker-compose.yaml +++ b/proxy/docker-compose.yaml @@ -36,7 +36,7 @@ services: - "443:443" networks: - web - - proxy + - dockersocket volumes: - ${VOLUMES_PATH}/letsencrypt:/letsencrypt - $PWD/tls.toml:/etc/traefik/tls.toml @@ -59,9 +59,12 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock:ro environment: - CONTAINERS: 1 + # grant privileges as environment variables: https://github.com/Tecnativa/docker-socket-proxy#grant-or-revoke-access-to-certain-api-sections + - CONTAINERS=1 + - INFO=1 networks: - - proxy + - dockersocket + privileged: true # whoami: @@ -80,4 +83,5 @@ services: networks: web: external: true - proxy: + dockersocket: + external: true