|
| 1 | +# cAdvisor |
| 2 | + |
| 3 | +This playbook can configure [cAdvisor](https://github.com/google/cadvisor) |
| 4 | + |
| 5 | +## Dependencies |
| 6 | + |
| 7 | +This service requires the following other services: |
| 8 | + |
| 9 | +- (optionally) [Traefik](traefik.md) - a reverse-proxy server for exposing cadvisor publicly |
| 10 | +- (optionally) [Prometheus](./prometheus.md) - a database for storing metrics |
| 11 | +- (optionally) [Grafana](./grafana.md) - a web UI that can query the prometheus datasource (connection) and display the logs |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +To enable this service, add the following configuration to your `vars.yml` file and re-run the [installation](../installing.md) process: |
| 16 | + |
| 17 | +```yaml |
| 18 | +######################################################################## |
| 19 | +# # |
| 20 | +# cadvisor # |
| 21 | +# # |
| 22 | +######################################################################## |
| 23 | + |
| 24 | +cadvisor_enabled: true |
| 25 | +# You will have to mount specific folders depending on your need |
| 26 | +# cadvisor_container_extra_arguments: |
| 27 | +# - "--mount type=bind,source=/,destination=/rootfs,readonly" |
| 28 | +# - "--mount type=bind,source=/sys,destination=/sys,readonly" |
| 29 | +# - "--mount type=bind,source=/var/lib/docker/,destination=/var/lib/docker,readonly" |
| 30 | +# - "--mount type=bind,source=/dev/disk/,destination=/dev/disk,readonly" |
| 31 | + |
| 32 | +######################################################################## |
| 33 | +# # |
| 34 | +# /cadvisor # |
| 35 | +# # |
| 36 | +######################################################################## |
| 37 | +``` |
| 38 | + |
| 39 | +See the full list of options in the [default/main.yml](default/main.yml) file |
| 40 | + |
| 41 | +cAdvisor can scrape metrics from system and containers. These metrics can be : |
| 42 | + |
| 43 | +- Displayed on the cAdvisor Web UI |
| 44 | +- Exposed to a metric-storage server like [Prometheus](./prometheus.md). |
| 45 | + |
| 46 | +## Exposing publicly the Web UI |
| 47 | + |
| 48 | +To expose cAdvisor to the web, you need to assign a hostname in `cadvisor_hostname` and optionally a path-prefix. |
| 49 | + |
| 50 | +```yaml |
| 51 | +# To expose the metrics publicly, enable and configure the lines below: |
| 52 | +cadvisor_hostname: mash.example.com |
| 53 | +cadvisor_path_prefix: / |
| 54 | + |
| 55 | +# To protect the metrics with HTTP Basic Auth, enable and configure the lines below. |
| 56 | +# See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users |
| 57 | +cadvisor_container_labels_traefik_middleware_basic_auth_enabled: true |
| 58 | +cadvisor_container_labels_traefik_middleware_basic_auth_users: "" |
| 59 | +``` |
| 60 | +
|
| 61 | +### Exposing metrics publicly |
| 62 | +
|
| 63 | +Unless you're scraping the cadvisor metrics from a local [Prometheus](prometheus.md) instance, as described in [Integrating with Prometheus](cadvisor.md#), you will probably wish to expose the metrics publicly so that a remote Prometheus instance can fetch them. When exposing publicly, it's natural to set up [HTTP Basic Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) **or anyone would be able to read your metrics**. |
| 64 | +
|
| 65 | +```yaml |
| 66 | +cadvisor_container_labels_metrics_enabled: true |
| 67 | + |
| 68 | +# To expose the metrics publicly, enable and configure the lines below: |
| 69 | +<!-- cadvisor_hostname: mash.example.com --> |
| 70 | +<!-- cadvisor_path_prefix: /metrics/mash-cadvisor --> |
| 71 | + |
| 72 | +# To protect the metrics with HTTP Basic Auth, enable and configure the lines below. |
| 73 | +# See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users |
| 74 | +cadvisor_container_labels_metrics_middleware_basic_auth_enabled: true |
| 75 | +cadvisor_container_labels_metrics_middleware_basic_auth_users: "" |
| 76 | +``` |
| 77 | +
|
| 78 | +## Integrating with Prometheus |
| 79 | +
|
| 80 | +cAdvisor can expose its metrics to [Prometheus](./prometheus.md). |
| 81 | +
|
| 82 | +### Prerequesites |
| 83 | +
|
| 84 | +The bare minimium is to ensure Prometheus can reach cadvisor. |
| 85 | +
|
| 86 | +- If cadvisor is on a different host than Prometheus, refer to section [Expose metrics publicly](cadvisor.md#) |
| 87 | +- If cadvisor is on the same host than prometheus, refer to section [Ensure Prometheus is on the same container network as cadvisor.](cadvisor.md#) |
| 88 | +
|
| 89 | +### Ensure Prometheus is on the same container network as cAdvisor. |
| 90 | +
|
| 91 | +If you are using MASH playbook, cadvisor should already be connected to prometheus container network |
| 92 | +
|
| 93 | +If cadvisor and prometheus do not share a network, you will have to |
| 94 | +
|
| 95 | +- Either connect Prometheus container network to cadvisor by editing `prometheus_container_additional_networks_auto` |
| 96 | +- Either connect cadvisor container network to Prometheus by editing `cadvisor_container_additional_networks_custom` |
| 97 | + |
| 98 | +Exemple: |
| 99 | + |
| 100 | +```yaml |
| 101 | +prometheus_container_additional_networks: |
| 102 | + - "{{ cadvisor_container_network }}" |
| 103 | +``` |
| 104 | + |
| 105 | +### Write the scrape config for prometheus |
| 106 | + |
| 107 | +# Healthcheck |
| 108 | + |
| 109 | +```yaml |
| 110 | +cadvisor_environment_variables_extension: | |
| 111 | +
|
| 112 | +# CADVISOR_HEALTHCHECK_URL=http://localhost:8080/cadvisor/healthz |
| 113 | +``` |
| 114 | + |
| 115 | +## Usage |
| 116 | + |
| 117 | +After [installing](../installing.md), refer to the documentation of [cAdvisor](https://github.com/google/cadvisor). |
0 commit comments