Compare commits

..

No commits in common. "1eff4b7e5115c8f0afb982d522a177c72883c036" and "681b7b2d72d8322f66374253c32a3aaf4af9d31c" have entirely different histories.

24 changed files with 95 additions and 173 deletions

View File

@ -35,7 +35,34 @@ ansible-playbook playbook/myhost.yml -t prometheus -e "exporter_upgrade=yes"
Role variables
--------------
- [Variables](docs/variables.md)
| Variable | Type | Choices | Default | Comment |
|----------------------------------------------|---------|------------------------------------------------------------------------------------|-------------------------|-----------------|
| 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
------------

View File

@ -26,11 +26,6 @@ prometheus_repo_postgres: prometheus-community
prometheus_repo_redis: 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
prometheus_nodes_ip:
localhost: "127.0.0.1"

View File

@ -1,80 +0,0 @@
# 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

@ -4,23 +4,50 @@
- set_fact:
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'
file:
state: directory
path: /tmp/prometheus_exporter/{{ exporter }}
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- 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//"
register: prometheus_exporter_latest_version
run_once: true
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | download from origin'
- name: '{{ exporter }} exporter | download'
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"
dest: /tmp/prometheus_exporter/{{ exporter }}/
ignore_errors: '{{ ansible_check_mode }}'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
- name: '{{ exporter }} exporter | unarchive'
@ -28,6 +55,7 @@
remote_src: yes
src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}.tar.gz
dest: /tmp/prometheus_exporter/{{ exporter }}/
when: not stat_result.stat.exists or exporter_upgrade == "yes"
ignore_errors: '{{ ansible_check_mode }}'
tags: [ 'prometheus_{{ exporter }}' ]
@ -41,6 +69,7 @@
mode: 0755
notify:
- '{{ exporter }}-exporter-restart'
when: not stat_result.stat.exists or exporter_upgrade == "yes"
tags: [ 'prometheus_{{ exporter }}' ]
ignore_errors: '{{ ansible_check_mode }}'
@ -48,3 +77,25 @@
file:
state: absent
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 }}' ]

View File

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

View File

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

View File

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

View File

@ -1,12 +0,0 @@
---
- 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 }}' ]

View File

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

View File

@ -1,47 +0,0 @@
---
- 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

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

View File

@ -1,5 +1,5 @@
---
- include_tasks: ../common.yml
- include_tasks: _common.yml
tags: ['prometheus_mongodb_exporter']
- 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']
- name: 'mysqld exporter | configuration'

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +0,0 @@
---
- 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_varnish_exporter']

View File

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

View File

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