You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.0 KiB

- name: Set up Prometheus
hosts: lotus-land-story
2 years ago
vars_files:
- vars.yml
2 months ago
vars:
2 months ago
prometheus_version: v2.54.1
2 months ago
cadvisor_version: v0.49.1
tasks:
- name: Install host exporters
ansible.builtin.apt:
pkg:
- prometheus-node-exporter
- prometheus-postgres-exporter
state: present
- name: Configure node-exporter
ansible.builtin.lineinfile:
dest: /etc/default/prometheus-node-exporter
regexp: '^ARGS='
# Include filesystems under /mnt
line: ARGS='--collector.filesystem.ignored-mount-points="^/(dev|proc|run|sys|media|var/lib/docker/.+)($|/)"'
state: present
# /usr/share/doc/prometheus-postgres-exporter/README.Debian
- name: Configure postgres-exporter
ansible.builtin.lineinfile:
dest: /etc/default/prometheus-postgres-exporter
regexp: '^DATA_SOURCE_NAME='
line: "DATA_SOURCE_NAME='user=prometheus host=/run/postgresql dbname=postgres'"
state: present
- name: Create Prometheus dir
ansible.builtin.file:
path: /mnt/lotus-land-story/prometheus
state: directory
2 years ago
owner: prometheus
group: prometheus
mode: "0755"
- name: Prometheus config
2 years ago
ansible.builtin.template:
dest: /mnt/lotus-land-story/prometheus/prometheus.yml
2 years ago
src: templates/prometheus.yml
owner: prometheus
group: prometheus
mode: "0600"
- name: Create Prometheus volume
community.docker.docker_volume:
name: prometheus
2 years ago
- name: Get prometheus user info
ansible.builtin.user:
name: prometheus
register: prometheus_user
- name: Run Prometheus
community.docker.docker_container:
name: prometheus
2 months ago
image: prom/prometheus:{{ prometheus_version }}
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.retention.size=5GB
- --log.format=json
restart: true
2 years ago
user: "{{ prometheus_user.uid }}"
groups: "{{ prometheus_user.group }}"
volumes:
- /mnt/lotus-land-story/prometheus:/etc/prometheus
- prometheus:/prometheus
restart_policy: unless-stopped
networks:
- name: lotus_land_story
etc_hosts:
host.docker.internal: host-gateway
2 months ago
- name: Run cAdvisor
community.docker.docker_container:
name: cadvisor
image: gcr.io/cadvisor/cadvisor:{{ cadvisor_version }}
restart: true
command:
#https://github.com/google/cadvisor/issues/2523#issuecomment-2258042352
- "--housekeeping_interval=30s"
- "--docker_only=true"
- "--store_container_labels=false"
2 months ago
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /etc/machine-id:/etc/machine-id:ro
2 months ago
restart_policy: unless-stopped
networks:
- name: lotus_land_story
# vim: ft=yaml.ansible