Skip to content

Commit

Permalink
enhancement: adding env/container labels options
Browse files Browse the repository at this point in the history
Add following
- cadvisor_env_metadata_whitelist
- cadvisor_whitelisted_container_labels
- cadvisor_store_container_labels

Tested with this simple playbook:
---
- name: Install cAdvisor
  hosts: localhost
  become: yes
  tasks:
    - name: Import cAdvisor role
      import_role:
        name: cadvisor
      vars:
        cadvisor_docker_only: true
        cadvisor_enable_metrics: [ "cpu", "memory", "network", "oom_event" ]
        cadvisor_whitelisted_container_labels: [ "com.docker.compose.oneoff" ]
        cadvisor_env_metadata_whitelist: [ "JEKYLL_ENV", "PATH" ]
        cadvisor_store_container_labels: false

Also tested dropping the options, which is why I decided to explicitly set
store_container_labels: true (which is the cadvisor default).

Closes: #403
Signed-off-by: Bryan Quigley <[email protected]>
  • Loading branch information
BryanQuigley committed Aug 2, 2024
1 parent dc94de0 commit 61cc69c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions roles/cadvisor/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cadvisor_prometheus_endpoint: "/metrics"

cadvisor_enable_metrics: []
cadvisor_disable_metrics: []
cadvisor_env_metadata_whitelist: []
cadvisor_whitelisted_container_labels: []
cadvisor_store_container_labels: true
cadvisor_docker_only: false

cadvisor_binary_install_dir: "/usr/local/bin"
Expand Down
12 changes: 12 additions & 0 deletions roles/cadvisor/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ argument_specs:
default: []
type: "list"
choices: *metrics_choices
cadvisor_store_container_labels:
description: "do not store all container labels"
type: "bool"
default: false
cadvisor_whitelisted_container_labels:
description: "comma-separated list of container labels to be used as labels on prometheus metrics"
default: []
type: "list"
cadvisor_env_metadata_whitelist:
description: "comma-separated list of env variables to be used as labels on prometheus metrics"
default: []
type: "list"
cadvisor_docker_only:
description: "do not report raw cgroup metrics, except the root cgroup"
type: "bool"
Expand Down
3 changes: 3 additions & 0 deletions roles/cadvisor/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ provisioner:
- network
- cpu
cadvisor_docker_only: true
whitelisted_container_labels: [ "com.docker.compose.image" ]
env_metadata_whitelist: [ "PATH" ]
store_container_labels: false
7 changes: 7 additions & 0 deletions roles/cadvisor/templates/cadvisor.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ ExecStart={{ cadvisor_binary_install_dir }}/cadvisor \
{% if cadvisor_docker_only %}
'--docker_only={{ cadvisor_docker_only | lower }}' \
{% endif -%}
{% if cadvisor_whitelisted_container_labels | length > 0 %}
'--whitelisted_container_labels={{ cadvisor_whitelisted_container_labels | join(',') }}' \
{% endif -%}
{% if cadvisor_env_metadata_whitelist | length > 0 %}
'--env_metadata_whitelist={{ cadvisor_env_metadata_whitelist | join(',') }}' \
{% endif %}
'--store_container_labels={{ cadvisor_store_container_labels | lower }}' \
'--listen_ip={{ cadvisor_listen_ip }}' \
'--port={{ cadvisor_port }}' \
'--prometheus_endpoint={{ cadvisor_prometheus_endpoint }}'
Expand Down

0 comments on commit 61cc69c

Please sign in to comment.