From 22c2c39818127d6c090f98ad001b15cbc3fdd690 Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Fri, 11 Nov 2022 23:51:52 +0100 Subject: [PATCH] big refacto - might have break things --- README.md | 39 +++++++++++--- defaults/main.yml | 60 ++++++++++++++------- example_file.yml | 22 +------- tasks/exporter/_common.yml | 99 +++++++++++++++++++++++++++++++++++ tasks/exporter/apache.yml | 44 +--------------- tasks/exporter/blackbox.yml | 46 +--------------- tasks/exporter/memcached.yml | 57 +------------------- tasks/exporter/mongodb.yml | 48 +---------------- tasks/exporter/mysqld.yml | 44 +--------------- tasks/exporter/node.yml | 44 +--------------- tasks/exporter/opcache.yml | 38 +------------- tasks/exporter/phpfpm.yml | 44 +--------------- tasks/exporter/postgresql.yml | 45 +--------------- tasks/exporter/redis.yml | 42 +-------------- tasks/exporter/varnish.yml | 44 +--------------- tasks/main.yml | 2 +- tasks/server/prometheus.yml | 2 +- 17 files changed, 196 insertions(+), 524 deletions(-) create mode 100644 tasks/exporter/_common.yml diff --git a/README.md b/README.md index 6ca6afd..06a157c 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,32 @@ prometheus The present role : - installs prometheus server inside a Docker container - installs various prometheus exporter + - node + - blackbox + - apache + - varnish + - php-fpm + - opcache + - redis + - memcached + - mysql + - postgres + - mongodb -It has been tested on : +Please note that Docker and Haproxy their own embedded exporters. + - https://docs.docker.com/config/daemon/prometheus/ + - https://www.haproxy.com/fr/blog/haproxy-exposes-a-prometheus-metrics-endpoint/ + +The role has been successfully tested on : - Debian 9 - Debian 10 + - Debian 11 + +Forced upgrade of installed exporters can be done by setting the extra parameters "exporter_upgrade" to "yes". + +``` +ansible-playbook playbook/myhost.yml -t prometheus -e "exporter_upgrade=yes" +``` Role variables -------------- @@ -79,12 +101,15 @@ Example variables TODO ---- - - add options to memcacged exporter launch - - --memcached.address="localhost:11211" - - --memcached.timeout=1s - - --memcached.pid-file="" - - handle multi instances for memcached exporter - + - documentation + - review / enhance documentation + - memcached + - add options to exporter launch + - --memcached.address="localhost:11211" + - --memcached.timeout=1s + - --memcached.pid-file="" + - handle multi instances for memcached exporter + License ------- diff --git a/defaults/main.yml b/defaults/main.yml index 455f2a8..36583d3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,30 +1,29 @@ --- -awh_services_docker_pull: "no" +prometheus_docker_pull: "no" -prometheus_apache_port: 8080 +exporter_upgrade: "" -prometheus_exporter_packages: [] +prometheus_os: "linux" +prometheus_arch: "amd64" +## repos url +prometheus_repo: "" +prometheus_repo_apache: Lusitaniae +prometheus_repo_blackbox: prometheus +prometheus_repo_memcached: prometheus +prometheus_repo_mongodb: percona +prometheus_repo_mysqld: prometheus +prometheus_repo_node: prometheus +prometheus_repo_opcache: MyOnlineStore +prometheus_repo_phpfpm: Lusitaniae +prometheus_repo_postgres: prometheus-community +prometheus_repo_redis: oliver006 +prometheus_repo_varnish: jonnenauha + +## server prometheus_nodes_ip: localhost: "127.0.0.1" -prometheus_mongodb_exporter_database: "admin" -prometheus_mongodb_exporter_host: "localhost" -prometheus_mongodb_exporter_port: 27017 - -prometheus_phpfpm_sockets_directory: "/run/php/" -prometheus_phpfpm_sockets_directory_additional: "/var/run/php*.sock" - -prometheus_opcache_exporter_fcgi_uri: "unix:///var/run/www.sock" - -prometheus_postgres_exporter_systemd_user: "postgres" -prometheus_postgres_exporter_host: "/var/run/postgresql/" -prometheus_postgres_exporter_sslmode: "disable" -prometheus_postgres_exporter_user: "postgres" -prometheus_postgres_exporter_password: "changeme_" -prometheus_postgres_exporter_port: 5432 - - prometheus_retention_time: "15d" prometheus_server_enable: false @@ -35,8 +34,29 @@ prometheus_server_scrape_interval: 5 prometheus_server_scrape_timeout: 5 prometheus_server_version: "latest" +## exporter +prometheus_exporter_packages: [] + +prometheus_apache_port: 8080 + prometheus_blackbox_exporter_host: localhost +prometheus_mongodb_exporter_database: "admin" +prometheus_mongodb_exporter_host: "localhost" +prometheus_mongodb_exporter_port: 27017 + +prometheus_opcache_exporter_fcgi_uri: "unix:///var/run/www.sock" + +prometheus_phpfpm_sockets_directory: "/run/php/" +prometheus_phpfpm_sockets_directory_additional: "/var/run/php*.sock" + +prometheus_postgres_exporter_systemd_user: "postgres" +prometheus_postgres_exporter_host: "/var/run/postgresql/" +prometheus_postgres_exporter_sslmode: "disable" +prometheus_postgres_exporter_user: "postgres" +prometheus_postgres_exporter_password: "changeme_" +prometheus_postgres_exporter_port: 5432 + prometheus_redis_exporter_addr: "redis://localhost:6379" prometheus_redis_exporter_user: "" prometheus_redis_exporter_password: "" diff --git a/example_file.yml b/example_file.yml index c0b118c..cb6836d 100644 --- a/example_file.yml +++ b/example_file.yml @@ -1,6 +1,6 @@ --- prometheus_server_enable: 'true' -prometheus_server_monitor: 'wac' +prometheus_server_monitor: 'foo' prometheus_exporter_packages: - node @@ -8,55 +8,41 @@ prometheus_exporter_packages: - apache prometheus_node_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_phpfpm_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_apache_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_haproxy_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_varnish_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_mysqld_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_mysqld_exporter_custom: - # PPD preprod-server1: environment: 'preprod' service_name: 'preprod' cluster: 'preprod' node_name: preprod-server1 - # PRD prod-server1: environment: 'prod' service_name: 'prod-bdd1' @@ -69,27 +55,21 @@ prometheus_mysqld_exporter_custom: node_name: prod-server2 prometheus_redis_multi_instances_exporter_targets: - # PPD - redis://preprod-server1:6379 - redis://preprod-server1:6380 - redis://preprod-server1:6381 - redis://preprod-server1:6382 - # PROD - redis://prod-server1:6379 - redis://prod-server2:6379 - redis://prod-server2:6380 prometheus_redis_exporter_targets: - # PPD - preprod-server1 - # PRD - prod-server1 - prod-server2 prometheus_nodes_ip: - # PPD preprod-server1 : 10.0.1.10 - # PRD prod-server1 : 10.0.1.11 prod-server2 : 10.0.1.12 diff --git a/tasks/exporter/_common.yml b/tasks/exporter/_common.yml new file mode 100644 index 0000000..d41a73d --- /dev/null +++ b/tasks/exporter/_common.yml @@ -0,0 +1,99 @@ +--- + +# to build prometheus repo for another var: https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#when-should-i-use-also-how-to-interpolate-variables-or-dynamic-variable-names +- 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//" + args: + warn: false + 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' + 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 }}/ + when: not stat_result.stat.exists or exporter_upgrade == "yes" + tags: [ 'prometheus_{{ exporter }}' ] + +- name: '{{ exporter }} exporter | unarchive' + unarchive: + 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" + tags: [ 'prometheus_{{ exporter }}' ] + +- name: '{{ exporter }} exporter | move to /usr/local/bin' + copy: + src: /tmp/prometheus_exporter/{{ exporter }}/{{ exporter }}_exporter-{{ prometheus_exporter_latest_version.stdout }}.{{ prometheus_os }}-{{ prometheus_arch }}/{{ exporter }}_exporter + dest: /usr/local/bin/prometheus-{{ exporter }}-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + notify: + - 'prometheus | {{ exporter }} exporter | restart service' + when: not stat_result.stat.exists or exporter_upgrade == "yes" + tags: [ 'prometheus_{{ exporter }}' ] + +- name: '{{ exporter }} exporter | cleanup temp path' + 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: + - 'prometheus | {{ exporter }} exporter | restart service' + when: not stat_result.stat.exists or exporter_upgrade == "yes" + tags: [ 'prometheus_{{ exporter }}' ] + +- name: '{{ exporter }} exporter | systemd | enable {{ exporter }}' + 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 }}' ] diff --git a/tasks/exporter/apache.yml b/tasks/exporter/apache.yml index a5bf098..9df2248 100644 --- a/tasks/exporter/apache.yml +++ b/tasks/exporter/apache.yml @@ -1,43 +1,3 @@ --- -- name: 'apache exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/Lusitaniae/apache_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_apache_exporter_latest_version - run_once: true - -- name: 'apache exporter | download' - get_url: - url: https://github.com/Lusitaniae/apache_exporter/releases/download/v{{ prometheus_apache_exporter_version|default(prometheus_apache_exporter_latest_version.stdout) }}/apache_exporter-{{ prometheus_apache_exporter_version|default(prometheus_apache_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'apache exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/apache_exporter-{{ prometheus_apache_exporter_version|default(prometheus_apache_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'apache exporter | move to /usr/local/bin' - copy: - src: /tmp/apache_exporter-{{ prometheus_apache_exporter_version|default(prometheus_apache_exporter_latest_version.stdout) }}.linux-amd64/apache_exporter - dest: /usr/local/bin/prometheus-apache-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | apache exporter | restart service' - -- name: 'apache exporter | install unit file to systemd' - template: - src: systemd/prometheus-apache-exporter.service.j2 - dest: /etc/systemd/system/prometheus-apache-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'prometheus | apache exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-apache-exporter.service +- include_tasks: _common.yml + tags: ['prometheus_apache'] diff --git a/tasks/exporter/blackbox.yml b/tasks/exporter/blackbox.yml index e31cd54..e1c4933 100644 --- a/tasks/exporter/blackbox.yml +++ b/tasks/exporter/blackbox.yml @@ -1,32 +1,6 @@ --- -- name: 'blackbox exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/prometheus/blackbox_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_blackbox_exporter_latest_version - run_once: true - -- name: 'blackbox exporter | download' - get_url: - url: https://github.com/prometheus/blackbox_exporter/releases/download/v{{ prometheus_blackbox_exporter_version|default(prometheus_blackbox_exporter_latest_version.stdout) }}/blackbox_exporter-{{ prometheus_blackbox_exporter_version|default(prometheus_blackbox_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'blackbox exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/blackbox_exporter-{{ prometheus_blackbox_exporter_version|default(prometheus_blackbox_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'blackbox exporter | move to /usr/local/bin' - copy: - src: /tmp/blackbox_exporter-{{ prometheus_blackbox_exporter_version|default(prometheus_blackbox_exporter_latest_version.stdout) }}.linux-amd64/blackbox_exporter - dest: /usr/local/bin/prometheus-blackbox-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | blackbox exporter | restart service' +- include_tasks: _common.yml + tags: ['prometheus_blackbox'] - name: 'blackbox exporter | configuration' template: @@ -38,19 +12,3 @@ register: prometheus_blackbox_exporter_configuration notify: - 'prometheus | blackbox exporter | restart service' - -- name: 'blackbox exporter | install unit file to systemd' - template: - src: systemd/prometheus-blackbox-exporter.service.j2 - dest: /etc/systemd/system/prometheus-blackbox-exporter.service - owner: root - group: root - mode: 0600 - notify: - - 'prometheus | blackbox exporter | restart service' - -- name: 'blackbox exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-blackbox-exporter.service diff --git a/tasks/exporter/memcached.yml b/tasks/exporter/memcached.yml index 00f46e5..7e3a8f8 100644 --- a/tasks/exporter/memcached.yml +++ b/tasks/exporter/memcached.yml @@ -1,56 +1,3 @@ --- -- name: 'memcached exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/prometheus/memcached_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_memcached_exporter_latest_version - run_once: true - -- name: 'prometheus | memcached exporter | download' - get_url: - url: https://github.com/prometheus/memcached_exporter/releases/download/v{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}/memcached_exporter-{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'memcached exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/memcached_exporter-{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'memcached exporter | move to /usr/local/bin' - copy: - src: /tmp/memcached_exporter-{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64/memcached_exporter - dest: /usr/local/bin/prometheus-memcached-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | memcached exporter | restart service' - -- name: 'memcached exporter | install unit file to systemd' - template: - src: systemd/prometheus-memcached-exporter.service.j2 - dest: /etc/systemd/system/prometheus-memcached-exporter.service - owner: root - group: root - mode: 0600 - notify: - - 'prometheus | memcached exporter | restart service' - -# - name: 'memcached exporter | configuration' -# template: -# src: conf/prometheus-memcached-exporter.j2 -# dest: /etc/default/prometheus-memcached-exporter -# owner: root -# group: root -# mode: 0600 -# register: prometheus_memcached_exporter_configuration -# notify: -# - 'prometheus | memcached exporter | restart service' - -- name: 'memcached exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-memcached-exporter.service +- include_tasks: _common.yml + tags: ['prometheus_memcached'] diff --git a/tasks/exporter/mongodb.yml b/tasks/exporter/mongodb.yml index 8299d9e..889aa78 100644 --- a/tasks/exporter/mongodb.yml +++ b/tasks/exporter/mongodb.yml @@ -1,21 +1,6 @@ --- -- name: 'mongodb exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/percona/mongodb_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_mongodb_exporter_latest_version - run_once: true - -- name: 'mongodb exporter | download' - get_url: - url: https://github.com/percona/mongodb_exporter/releases/download/v{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'mongodb exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp +- include_tasks: _common.yml + tags: ['prometheus_mongodb'] - name: 'mongodb exporter < v0.2 | move to /usr/local/bin' copy: @@ -30,19 +15,6 @@ when: - prometheus_mongodb_exporter_latest_version.stdout < '0.2' -- name: 'mongodb exporter > v0.2 | move to /usr/local/bin' - copy: - src: /tmp/mongodb_exporter-{{ prometheus_mongodb_exporter_version|default(prometheus_mongodb_exporter_latest_version.stdout) }}.linux-amd64/mongodb_exporter - dest: /usr/local/bin/prometheus-mongodb-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | mongodb exporter | restart service' - when: - - prometheus_mongodb_exporter_latest_version.stdout > '0.2' - - name: 'mongodb exporter | configuration' template: src: conf/prometheus-mongodb-exporter.j2 @@ -52,19 +24,3 @@ mode: 0600 notify: - 'prometheus | mongodb exporter | restart service' - -- name: 'mongodb exporter | install unit file to systemd' - template: - src: systemd/prometheus-mongodb-exporter.service.j2 - dest: /etc/systemd/system/prometheus-mongodb-exporter.service - owner: root - group: root - mode: 0600 - notify: - - 'prometheus | mongodb exporter | restart service' - -- name: 'mongodb exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-mongodb-exporter.service diff --git a/tasks/exporter/mysqld.yml b/tasks/exporter/mysqld.yml index 05a65dc..b3decc6 100644 --- a/tasks/exporter/mysqld.yml +++ b/tasks/exporter/mysqld.yml @@ -1,32 +1,6 @@ --- -- name: 'mysqld exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_mysqld_exporter_latest_version - run_once: true - -- name: 'mysqld exporter | download' - get_url: - url: https://github.com/prometheus/mysqld_exporter/releases/download/v{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}/mysqld_exporter-{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'mysqld exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'mysqld exporter | move to /usr/local/bin' - copy: - src: /tmp/mysqld_exporter-{{ prometheus_mysqld_exporter_version|default(prometheus_mysqld_exporter_latest_version.stdout) }}.linux-amd64/mysqld_exporter - dest: /usr/local/bin/prometheus-mysqld-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | mysqld exporter | restart service' +- include_tasks: _common.yml + tags: ['prometheus_mysqld'] - name: 'mysqld exporter | configuration' template: @@ -40,17 +14,3 @@ register: prometheus_mysqld_exporter_configuration notify: - 'prometheus | mysqld exporter | restart service' - -- name: 'mysqld exporter | install unit file to systemd' - template: - src: systemd/prometheus-mysqld-exporter.service.j2 - dest: /etc/systemd/system/prometheus-mysqld-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'mysqld exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-mysqld-exporter.service diff --git a/tasks/exporter/node.yml b/tasks/exporter/node.yml index 745e9f1..8b9e233 100644 --- a/tasks/exporter/node.yml +++ b/tasks/exporter/node.yml @@ -1,43 +1,3 @@ --- -- name: 'node exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/prometheus/node_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_node_exporter_latest_version - run_once: true - -- name: 'node exporter | download' - get_url: - url: https://github.com/prometheus/node_exporter/releases/download/v{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'node exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'node exporter | move to /usr/local/bin' - copy: - src: /tmp/node_exporter-{{ prometheus_node_exporter_version|default(prometheus_node_exporter_latest_version.stdout) }}.linux-amd64/node_exporter - dest: /usr/local/bin/prometheus-node-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | node exporter | restart service' - -- name: 'node exporter | install unit file to systemd' - template: - src: systemd/prometheus-node-exporter.service.j2 - dest: /etc/systemd/system/prometheus-node-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'node exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-node-exporter.service +- include_tasks: _common.yml + tags: ['prometheus_node'] diff --git a/tasks/exporter/opcache.yml b/tasks/exporter/opcache.yml index cb9b252..284d727 100644 --- a/tasks/exporter/opcache.yml +++ b/tasks/exporter/opcache.yml @@ -1,26 +1,6 @@ --- -- name: 'opcache exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/MyOnlineStore/opcache-exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_opcache_exporter_latest_version - run_once: true - -- name: 'opcache exporter | download' - get_url: - url: https://github.com/MyOnlineStore/opcache-exporter/releases/download/v{{ prometheus_opcache_exporter_version|default(prometheus_opcache_exporter_latest_version.stdout) }}/opcache_exporter-{{ prometheus_opcache_exporter_version|default(prometheus_opcache_exporter_latest_version.stdout) }}-linux-amd64 - dest: /tmp - -- name: 'opcache exporter | move to /usr/local/bin' - copy: - src: /tmp/opcache_exporter-{{ prometheus_opcache_exporter_version|default(prometheus_opcache_exporter_latest_version.stdout) }}-linux-amd64 - dest: /usr/local/bin/prometheus-opcache-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | opcache exporter | restart service' +- include_tasks: _common.yml + tags: ['prometheus_opcache'] - name: 'opcache exporter | configuration' template: @@ -32,17 +12,3 @@ register: prometheus_opcache_exporter_configuration notify: - 'prometheus | opcache exporter | restart service' - -- name: 'opcache exporter | install unit file to systemd' - template: - src: systemd/prometheus-opcache-exporter.service.j2 - dest: /etc/systemd/system/prometheus-opcache-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'opcache exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-opcache-exporter.service diff --git a/tasks/exporter/phpfpm.yml b/tasks/exporter/phpfpm.yml index e672096..8fddb78 100644 --- a/tasks/exporter/phpfpm.yml +++ b/tasks/exporter/phpfpm.yml @@ -1,32 +1,6 @@ --- -- name: 'phpfpm exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/Lusitaniae/phpfpm_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_phpfpm_exporter_latest_version - run_once: true - -- name: 'phpfpm exporter | download' - get_url: - url: https://github.com/Lusitaniae/phpfpm_exporter/releases/download/v{{ prometheus_phpfpm_exporter_version|default(prometheus_phpfpm_exporter_latest_version.stdout) }}/phpfpm_exporter-{{ prometheus_phpfpm_exporter_version|default(prometheus_phpfpm_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'phpfpm exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/phpfpm_exporter-{{ prometheus_phpfpm_exporter_version|default(prometheus_phpfpm_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'phpfpm exporter | move to /usr/local/bin' - copy: - src: /tmp/phpfpm_exporter-{{ prometheus_phpfpm_exporter_version|default(prometheus_phpfpm_exporter_latest_version.stdout) }}.linux-amd64/phpfpm_exporter - dest: /usr/local/bin/prometheus-phpfpm-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'phpfpm exporter | restart service' +- include_tasks: _common.yml + tags: ['prometheus_phpfpm'] - name: 'phpfpm exporter | install startup script' template: @@ -37,17 +11,3 @@ mode: 0600 notify: - 'prometheus | phpfpm exporter | restart service' - -- name: 'phpfpm exporter | install unit file to systemd' - template: - src: systemd/prometheus-phpfpm-exporter.service.j2 - dest: /etc/systemd/system/prometheus-phpfpm-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'phpfpm exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-phpfpm-exporter.service diff --git a/tasks/exporter/postgresql.yml b/tasks/exporter/postgresql.yml index 4e3975d..55b179b 100644 --- a/tasks/exporter/postgresql.yml +++ b/tasks/exporter/postgresql.yml @@ -1,32 +1,6 @@ --- -- name: 'postgres exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/prometheus-community/postgres_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_postgres_exporter_latest_version - run_once: true - -- name: 'postgres exporter | download' - get_url: - url: https://github.com/prometheus-community/postgres_exporter/releases/download/v{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'postgres exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'postgres exporter | move to /usr/local/bin' - copy: - src: /tmp/postgres_exporter-{{ prometheus_postgres_exporter_version|default(prometheus_postgres_exporter_latest_version.stdout) }}.linux-amd64/postgres_exporter - dest: /usr/local/bin/prometheus-postgres-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | postgres exporter | restart service' +- include_tasks: _common.yml + tags: ['prometheus_postgres'] - name: 'postgres exporter | configuration' template: @@ -38,18 +12,3 @@ register: prometheus_postgres_exporter_configuration notify: - 'prometheus | postgres exporter | restart service' - -- name: 'postgres exporter | install unit file to systemd' - template: - src: systemd/prometheus-postgres-exporter.service.j2 - dest: /etc/systemd/system/prometheus-postgres-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'postgres exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - state: started - name: prometheus-postgres-exporter.service diff --git a/tasks/exporter/redis.yml b/tasks/exporter/redis.yml index b44a214..bb287ab 100644 --- a/tasks/exporter/redis.yml +++ b/tasks/exporter/redis.yml @@ -1,30 +1,6 @@ --- -- name: 'redis exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/oliver006/redis_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_redis_exporter_latest_version - run_once: true - -- name: 'redis exporter | download' - get_url: - url: https://github.com/oliver006/redis_exporter/releases/download/v{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}/redis_exporter-v{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'redis exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/redis_exporter-v{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'redis exporter | move to /usr/local/bin' - copy: - src: /tmp/redis_exporter-v{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}.linux-amd64/redis_exporter - dest: /usr/local/bin/prometheus-redis-exporter - remote_src: yes - owner: root - group: root - mode: 0755 +- include_tasks: _common.yml + tags: ['prometheus_redis'] - name: 'redis exporter | configuration' template: @@ -36,17 +12,3 @@ register: prometheus_redis_exporter_configuration notify: - 'prometheus | redis exporter | restart service' - -- name: 'redis exporter | install unit file to systemd' - template: - src: systemd/prometheus-redis-exporter.service.j2 - dest: /etc/systemd/system/prometheus-redis-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'redis exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-redis-exporter.service diff --git a/tasks/exporter/varnish.yml b/tasks/exporter/varnish.yml index b76d04b..9de2625 100644 --- a/tasks/exporter/varnish.yml +++ b/tasks/exporter/varnish.yml @@ -1,43 +1,3 @@ --- -- name: 'varnish exporter | get latest release from GitHub' - shell: curl --silent "https://api.github.com/repos/jonnenauha/prometheus_varnish_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" - args: - warn: false - register: prometheus_varnish_exporter_latest_version - run_once: true - -- name: 'varnish exporter | download' - get_url: - url: https://github.com/jonnenauha/prometheus_varnish_exporter/releases/download/{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}/prometheus_varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'varnish exporter | unarchive' - unarchive: - remote_src: yes - src: /tmp/prometheus_varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64.tar.gz - dest: /tmp - -- name: 'varnish exporter | move to /usr/local/bin' - copy: - src: /tmp/prometheus_varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64/prometheus_varnish_exporter - dest: /usr/local/bin/prometheus-varnish-exporter - remote_src: yes - owner: root - group: root - mode: 0755 - notify: - - 'prometheus | varnish exporter | restart service' - -- name: 'varnish exporter | install unit file to systemd' - template: - src: systemd/prometheus-varnish-exporter.service.j2 - dest: /etc/systemd/system/prometheus-varnish-exporter.service - owner: root - group: root - mode: 0600 - -- name: 'varnish exporter | configure systemd to use service' - systemd: - daemon_reload: yes - enabled: yes - name: prometheus-varnish-exporter.service +- include_tasks: _common.yml + tags: ['prometheus_varnish'] diff --git a/tasks/main.yml b/tasks/main.yml index a00f581..158ae21 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,7 +14,7 @@ ## include exporter install - name: 'exporters install' vars: - service: "{{ item }}" + exporter: "{{ item }}" include_tasks: "exporter/{{ item }}.yml" tags: - prometheus_node_exporter diff --git a/tasks/server/prometheus.yml b/tasks/server/prometheus.yml index fb8ceae..cea0106 100644 --- a/tasks/server/prometheus.yml +++ b/tasks/server/prometheus.yml @@ -62,7 +62,7 @@ log_options: tag: docker_prometheus restart_policy: 'unless-stopped' - pull: '{{ awh_services_docker_pull }}' + pull: '{{ prometheus_docker_pull }}' etc_hosts: '{{ prometheus_nodes_ip }}' tags: - prometheus