Compare commits

..

8 Commits

Author SHA1 Message Date
tom.chivert
1eff4b7e51 syntax 2023-07-20 16:02:33 +02:00
tom.chivert
8bc8db8334 typo ep2 2023-07-20 15:45:00 +02:00
tom.chivert
5b98397bbd typo 2023-07-20 15:43:24 +02:00
tom.chivert
78decc8f50 exporters reorganization 2023-07-20 15:40:35 +02:00
tom.chivert
f733ab6d2c update readme and variables documentation 2023-07-20 14:33:39 +02:00
tom.chivert
4581660f14 add docker-compose-plugin to dependencies 2023-07-20 11:55:06 +02:00
tom.chivert
d8afed3b98 syntax 2023-07-20 11:50:47 +02:00
tom.chivert
902af9c58d add new exporters binaries source 2023-07-20 11:47:31 +02:00
24 changed files with 173 additions and 95 deletions

View File

@ -35,34 +35,7 @@ ansible-playbook playbook/myhost.yml -t prometheus -e "exporter_upgrade=yes"
Role variables Role variables
-------------- --------------
| Variable | Type | Choices | Default | Comment | - [Variables](docs/variables.md)
|----------------------------------------------|---------|------------------------------------------------------------------------------------|-------------------------|-----------------|
| prometheus_server_enable | string | true / false | | |
| prometheus_server_version | string | | latest | |
| prometheus_server_monitor | string | | | |
| prometheus_server_global_scrape_interval | string | | 15 | |
| prometheus_server_global_evaluation_interval | string | | 15 | |
| prometheus_server_job_name | string | | prometheus | |
| prometheus_server_scrape_interval | string | | 5 | |
| prometheus_server_scrape_timeout | string | | 5 | |
| prometheus_exporter_packages | list | node / mysqld / postgresql / mongodb / phpfpm / apache / haproxy / varnish / redis | | |
| prometheus_node_exporter_targets | list | | | |
| prometheus_mysqld_exporter_targets | list | | | |
| prometheus_mongodb_exporter_targets | list | | | |
| prometheus_postgres_exporter_targets | list | | | |
| prometheus_redis_exporter_targets | list | | | |
| prometheus_proxysql_exporter_targets | list | | | [Enable exporter](https://proxysql.com/documentation/prometheus-exporter/) |
| prometheus_mysqld_exporter_user | string | | | |
| prometheus_mysqld_exporter_password | string | | | |
| prometheus_mongodb_exporter_host | string | | localhost | |
| prometheus_mongodb_exporter_port | string | | 27017 | |
| prometheus_mongodb_exporter_user | string | | | |
| prometheus_mongodb_exporter_pass | string | | | |
| prometheus_opcache_exporter_fcgi_uri | string | | unix:///var/run/www.sock| |
| prometheus_server_version | string | | latest | |
| prometheus_redis_exporter_addr | string | | redis://localhost:6379 | |
| prometheus_redis_exporter_user | string | | | |
| prometheus_redis_exporter_password | string | | | |
Dependencies Dependencies
------------ ------------

View File

@ -26,6 +26,11 @@ prometheus_repo_postgres: prometheus-community
prometheus_repo_redis: tchivert prometheus_repo_redis: tchivert
prometheus_repo_varnish: tchivert prometheus_repo_varnish: tchivert
prometheus_exporters_repo: "https://git.rznet.fr/tchivert/prometheus_exporters"
prometheus_exporters_release: "latest"
prometheus_exporters_sources: "repo"
# prometheus_exporters_sources: "origin"
## server ## server
prometheus_nodes_ip: prometheus_nodes_ip:
localhost: "127.0.0.1" localhost: "127.0.0.1"

80
docs/variables.md Normal file
View File

@ -0,0 +1,80 @@
# Variables
## Docker
| Variable Name | Description | Type | Default Value |
|---|---|---|---|
| docker_compose_directory | The directory where Docker Compose files are stored | String | "/opt/docker-compose" |
| docker_compose_bin | The Docker Compose binary to use | String | "docker compose" |
## Prometheus
| Variable Name | Description | Type | Default Value |
|---|---|---|---|
| prometheus_docker_network | The name of the Docker network for Prometheus containers | String | "prometheus" |
| prometheus_docker_pull | Whether to pull the Prometheus Docker image | String | "no" |
| prometheus_os | The operating system for Prometheus | String | "linux" |
| prometheus_arch | The architecture for Prometheus | String | "amd64" |
| prometheus_repo | The repository URL for Prometheus | String | "" |
| prometheus_nodes_ip | The IP addresses of Prometheus nodes | Dictionary | localhost: "127.0.0.1" |
| prometheus_retention_time | The retention time for Prometheus data | String | "15d" |
| prometheus_server_enable | Whether to enable the Prometheus server | Boolean | false |
| prometheus_server_global_evaluation_interval | The global evaluation interval for Prometheus server | Integer | 15 |
| prometheus_server_global_scrape_interval | The global scrape interval for Prometheus server | Integer | 15 |
| prometheus_server_job_name | The job name for Prometheus server | String | "prometheus" |
| prometheus_server_scrape_interval | The scrape interval for Prometheus server | Integer | 5 |
| prometheus_server_scrape_timeout | The scrape timeout for Prometheus server | Integer | 5 |
| prometheus_server_version | The version of Prometheus server to install | String | "latest" |
## Prometheus Exporters
| Variable Name | Description | Type | Default Value |
|---|---|---|---|
| exporter_upgrade | Whether to upgrade the exporter | String | "" |
| prometheus_exporters_repo | The repository URL for Prometheus exporters | String | "https://git.rznet.fr/tchivert/prometheus_exporters" |
| prometheus_exporters_release | The release version of Prometheus exporters | String | "latest" |
| prometheus_exporters_sources | The source of Prometheus exporters (repo or origin) | String | "repo" |
| prometheus_repo_apache | Apache exporter repository | String | Lusitaniae |
| prometheus_repo_blackbox | Blackbox exporter repository | String | prometheus |
| prometheus_repo_memcached | Memcached exporter repository | String | prometheus |
| prometheus_repo_mongodb | MongoDB exporter repository | String | percona |
| prometheus_repo_mysqld | MySQLd exporter repository | String | prometheus |
| prometheus_repo_nginx | Nginx exporter repository | String | tchivert |
| prometheus_repo_node | Node exporter repository | String | prometheus |
| prometheus_repo_opcache | Opcache exporter repository | String | tchivert |
| prometheus_repo_phpfpm | PHP-FPM exporter repository | String | Lusitaniae |
| prometheus_repo_postgres | Postgres exporter repository | String | prometheus-community |
| prometheus_repo_redis | Redis exporter repository | String | tchivert |
| prometheus_repo_varnish | Varnish exporter repository | String | tchivert |
| prometheus_exporter_packages | The list of exporter packages to install | List | [] |
| prometheus_apache_port | The port for Apache exporter | Integer | 8080 |
| prometheus_blackbox_exporter_host | The host for Blackbox exporter | String | localhost |
| prometheus_mongodb_exporter_database | The database for MongoDB exporter | String | "admin" |
| prometheus_mongodb_exporter_host | The host for MongoDB exporter | String | "localhost" |
| prometheus_mongodb_exporter_port | The port for MongoDB exporter | Integer | 27017 |
| prometheus_opcache_exporter_fcgi_uri | The FCGI URI for Opcache exporter | String | "unix:///var/run/www.sock" |
| prometheus_phpfpm_sockets_directory | The directory for PHP-FPM sockets | String | "/run/php/" |
| prometheus_postgres_exporter_systemd_user | The systemd user for Postgres exporter | String | "postgres" |
| prometheus_postgres_exporter_host | The host for Postgres exporter | String | "/var/run/postgresql/" |
| prometheus_postgres_exporter_sslmode | The SSL mode for Postgres exporter | String | "disable" |
| prometheus_postgres_exporter_user | The user for Postgres exporter | String | "postgres" |
| prometheus_postgres_exporter_password | The password for Postgres exporter | String | "changeme_" |
| prometheus_postgres_exporter_port | The port for Postgres exporter | Integer | 5432 |
| prometheus_redis_exporter_addr | The address for Redis exporter | String | "redis://localhost:6379" |
| prometheus_redis_exporter_user | The user for Redis exporter | String | "" |
| prometheus_redis_exporter_password | The password for Redis exporter | String | "" |
## Grafana
| Variable Name | Description | Type | Default Value |
|---|---|---|---|
| grafana_auth_anonymous_enabled | Whether anonymous authentication is enabled in Grafana | Boolean | false |
| grafana_auth_anonymous_org_role | The role for anonymous users in Grafana | String | Editor |
| grafana_auth_anonymous_org_name | The name of the organization for anonymous users in Grafana | String | 'Main Org.' |
| grafana_auth_disable_login_form | Whether to disable the login form in Grafana | Boolean | false |
| grafana_editors_can_admin | Whether editors can administer Grafana | Boolean | false |
| grafana_users_viewers_can_edit | Whether viewers can edit in Grafana | Boolean | false |
| grafana_log_level | The log level for Grafana | String | error |
| grafana_router_logging | Whether to enable router logging in Grafana | Boolean | false |
| grafana_disable_sanitize_html | Whether to disable HTML sanitization in Grafana | Boolean | true |
| grafana_traefik_entrypoint | The Traefik entrypoint for Grafana | String | 'websecure' |

View File

@ -0,0 +1,12 @@
---
- name: '{{ exporter }} exporter | stop old version'
systemd:
name: prometheus-{{ exporter }}-exporter.service
state: stopped
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | remove old version'
file:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
state: absent
tags: [ 'prometheus_{{ exporter }}' ]

47
tasks/exporter/common.yml Normal file
View File

@ -0,0 +1,47 @@
---
- name: '{{ exporter }} exporter | check if exporter is already installed'
stat:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
register: stat_result
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | remove old exporter version'
include_tasks: "cleanup.yml"
when: stat_result.stat.exists and exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | install from origin'
include_tasks: "origin.yml"
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "origin"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | install from repo'
include_tasks: "repo.yml"
when: >
(not stat_result.stat.exists or exporter_upgrade == "yes") and
prometheus_exporters_sources == "repo"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | systemd | copy unit file'
template:
src: systemd/prometheus-{{ exporter }}-exporter.service.j2
dest: /etc/systemd/system/prometheus-{{ exporter }}-exporter.service
owner: root
group: root
mode: 0600
notify:
- '{{ exporter }}-exporter-restart'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | systemd | enable service'
systemd:
daemon_reload: yes
enabled: yes
name: prometheus-{{ exporter }}-exporter.service
ignore_errors: '{{ ansible_check_mode }}'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]

View File

@ -8,7 +8,7 @@
failed_when: result.rc != 0 and result.rc != 127 failed_when: result.rc != 0 and result.rc != 127
with_items: with_items:
- docker - docker
- docker-compose - docker-compose-plugin
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | create docker-compose directory' - name: '{{ exporter }} exporter | create docker-compose directory'

View File

@ -4,50 +4,23 @@
- set_fact: - set_fact:
prometheus_repo: "{{ lookup('vars', 'prometheus_repo_' ~ exporter) }}" prometheus_repo: "{{ lookup('vars', 'prometheus_repo_' ~ exporter) }}"
#- name: debug
# debug:
# msg: "Repo: {{ prometheus_repo }}"
- name: '{{ exporter }} exporter | check if exporter is already install'
stat:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
register: stat_result
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | stop old version'
systemd:
name: prometheus-{{ exporter }}-exporter.service
state: stopped
when: exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | remove old version'
file:
path: /usr/local/bin/prometheus-{{ exporter }}-exporter
state: absent
when: exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | create temp path' - name: '{{ exporter }} exporter | create temp path'
file: file:
state: directory state: directory
path: /tmp/prometheus_exporter/{{ exporter }} path: /tmp/prometheus_exporter/{{ exporter }}
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | get latest release from GitHub' - name: '{{ exporter }} exporter | get latest release from GitHub'
shell: curl --silent "https://api.github.com/repos/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" shell: curl --silent "https://api.github.com/repos/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/latest" | jq -r .tag_name | sed "s/v//"
register: prometheus_exporter_latest_version register: prometheus_exporter_latest_version
run_once: true run_once: true
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | download' - name: '{{ exporter }} exporter | download from origin'
get_url: get_url:
url: "https://github.com/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/download/v{{ prometheus_exporter_latest_version.stdout }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz" url: "https://github.com/{{ prometheus_repo }}/{{ exporter }}_exporter/releases/download/v{{ prometheus_exporter_latest_version.stdout }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz"
dest: /tmp/prometheus_exporter/{{ exporter }}/ dest: /tmp/prometheus_exporter/{{ exporter }}/
ignore_errors: '{{ ansible_check_mode }}' ignore_errors: '{{ ansible_check_mode }}'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | unarchive' - name: '{{ exporter }} exporter | unarchive'
@ -55,7 +28,6 @@
remote_src: yes remote_src: yes
src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz
dest: /tmp/prometheus_exporter/{{ exporter }}/ dest: /tmp/prometheus_exporter/{{ exporter }}/
when: not stat_result.stat.exists or exporter_upgrade == "yes"
ignore_errors: '{{ ansible_check_mode }}' ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
@ -69,7 +41,6 @@
mode: 0755 mode: 0755
notify: notify:
- '{{ exporter }}-exporter-restart' - '{{ exporter }}-exporter-restart'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ] tags: [ 'prometheus_{{ exporter }}' ]
ignore_errors: '{{ ansible_check_mode }}' ignore_errors: '{{ ansible_check_mode }}'
@ -77,25 +48,3 @@
file: file:
state: absent state: absent
path: /tmp/prometheus_exporter/{{ exporter }} path: /tmp/prometheus_exporter/{{ exporter }}
- name: '{{ exporter }} exporter | systemd | copy unit file'
template:
src: systemd/prometheus-{{ exporter }}-exporter.service.j2
dest: /etc/systemd/system/prometheus-{{ exporter }}-exporter.service
owner: root
group: root
mode: 0600
notify:
- '{{ exporter }}-exporter-restart'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | systemd | enable service'
systemd:
daemon_reload: yes
enabled: yes
name: prometheus-{{ exporter }}-exporter.service
ignore_errors: '{{ ansible_check_mode }}'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]

11
tasks/exporter/repo.yml Normal file
View File

@ -0,0 +1,11 @@
---
- name: '{{ exporter }} exporter | download from repo'
get_url:
url: "{{prometheus_exporters_repo}}/releases/download/{{prometheus_exporters_release}}/{{exporter}}_exporter"
dest: /usr/local/bin/prometheus-{{ exporter }}-exporter
remote_src: yes
owner: root
group: root
mode: 0755
ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'prometheus_{{ exporter }}' ]

View File

@ -1,3 +1,3 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_apache_exporter'] tags: ['prometheus_apache_exporter']

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_blackbox_exporter'] tags: ['prometheus_blackbox_exporter']
- name: 'blackbox exporter | configuration' - name: 'blackbox exporter | configuration'

View File

@ -5,5 +5,5 @@
- cloudflare_api_key is defined - cloudflare_api_key is defined
tags: ['prometheus_cloudflare'] tags: ['prometheus_cloudflare']
- include_tasks: _docker.yml - include_tasks: ../docker.yml
tags: ['prometheus_cloudflare'] tags: ['prometheus_cloudflare']

View File

@ -1,3 +1,3 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_memcached_exporter'] tags: ['prometheus_memcached_exporter']

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_mongodb_exporter'] tags: ['prometheus_mongodb_exporter']
- name: 'mongodb exporter < v0.2 | move to /usr/local/bin' - name: 'mongodb exporter < v0.2 | move to /usr/local/bin'

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_mysqld_exporter'] tags: ['prometheus_mysqld_exporter']
- name: 'mysqld exporter | configuration' - name: 'mysqld exporter | configuration'

View File

@ -1,3 +1,3 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_nginx_exporter'] tags: ['prometheus_nginx_exporter']

View File

@ -1,3 +1,3 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_node_exporter'] tags: ['prometheus_node_exporter']

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_opcache_exporter'] tags: ['prometheus_opcache_exporter']
- name: 'opcache exporter | configuration' - name: 'opcache exporter | configuration'

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_phpfpm_exporter'] tags: ['prometheus_phpfpm_exporter']
- name: 'phpfpm exporter | install startup script' - name: 'phpfpm exporter | install startup script'

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_postgres_exporter'] tags: ['prometheus_postgres_exporter']
- name: 'postgres exporter | configuration' - name: 'postgres exporter | configuration'

View File

@ -1,5 +1,5 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_redis_exporter'] tags: ['prometheus_redis_exporter']
- name: 'redis exporter | configuration' - name: 'redis exporter | configuration'

View File

@ -1,3 +1,3 @@
--- ---
- include_tasks: _common.yml - include_tasks: ../common.yml
tags: ['prometheus_varnish_exporter'] tags: ['prometheus_varnish_exporter']

View File

@ -24,7 +24,7 @@
- name: 'exporters install' - name: 'exporters install'
vars: vars:
exporter: "{{ item }}" exporter: "{{ item }}"
include_tasks: "exporter/{{ item }}.yml" include_tasks: "exporter/services/{{ item }}.yml"
tags: tags:
- prometheus_node_exporter - prometheus_node_exporter
- prometheus_mysqld_exporter - prometheus_mysqld_exporter

View File

@ -9,5 +9,6 @@
name: name:
- curl - curl
- jq - jq
- docker-compose-plugin
state: present state: present
tags: ['prometheus'] tags: ['prometheus']