diff --git a/README.md b/README.md index d489eda..5415e40 100644 --- a/README.md +++ b/README.md @@ -12,28 +12,31 @@ It has been tested on : Role variables -------------- -| 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 | | | -| prometheus_node_exporter_targets | list | | | | -| prometheus_mysqld_exporter_targets | list | | | | -| prometheus_mongodb_exporter_targets | list | | | | -| prometheus_postgres_exporter_targets | list | | | | -| 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_server_version | string | | latest | | +| 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_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_server_version | string | | latest | | +| prometheus_redis_exporter_addr | string | | redis://localhost:6379 | | +| prometheus_redis_exporter_user | string | | | | +| prometheus_redis_exporter_password | string | | | | Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 29318e2..710909f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -33,3 +33,7 @@ prometheus_server_scrape_timeout: 5 prometheus_server_version: "latest" prometheus_blackbox_exporter_host: localhost + +prometheus_redis_exporter_addr: "redis://localhost:6379" +prometheus_redis_exporter_user: "" +prometheus_redis_exporter_password: "" diff --git a/handlers/main.yml b/handlers/main.yml index 0605da0..431d005 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -60,3 +60,10 @@ state: restarted enabled: yes tags: ['prometheus'] + +- name: 'prometheus | redis exporter | restart service' + systemd: + name: prometheus-redis-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] diff --git a/tasks/redis_exporter.yml b/tasks/redis_exporter.yml new file mode 100644 index 0000000..8b919aa --- /dev/null +++ b/tasks/redis_exporter.yml @@ -0,0 +1,54 @@ +--- +- name: 'prometheus | 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: 'prometheus | 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-{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}.linux-amd64.tar.gz + dest: /tmp + +- name: 'prometheus | redis exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/redis_exporter-{{ prometheus_redis_exporter_version|default(prometheus_redis_exporter_latest_version.stdout) }}.linux-amd64.tar.gz + dest: /tmp + +- name: 'prometheus | redis exporter | move to /usr/local/bin' + copy: + src: /tmp/redis_exporter-{{ 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 + notify: + - 'prometheus | redis exporter | restart service' + +- name: 'prometheus | redis exporter | configuration' + template: + src: conf/prometheus-redis-exporter.j2 + dest: /etc/default/prometheus-redis-exporter + owner: root + group: root + mode: 0600 + register: prometheu_postgres_exporter_configuration + notify: + - 'prometheus | postgres exporter | restart service' + +- name: 'prometheus | 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: 'prometheus | redis exporter | configure systemd to use service' + systemd: + daemon_reload: yes + enabled: yes + name: prometheus-redis-exporter.service diff --git a/templates/conf/prometheus-redis-exporter.j2 b/templates/conf/prometheus-redis-exporter.j2 new file mode 100644 index 0000000..50158b3 --- /dev/null +++ b/templates/conf/prometheus-redis-exporter.j2 @@ -0,0 +1,10 @@ +# {{ ansible_managed }} +{% if (prometheus_redis_exporter_addr is defined) %} +REDIS_ADDR={{ prometheus_redis_exporter_addr }} +{% endif %} +{% if (prometheus_redis_exporter_addr is defined) %} +REDIS_USER={{ prometheus_redis_exporter_user }} +{% endif %} +{% if (prometheus_redis_exporter_addr is defined) %} +REDIS_PASSWORD={{ prometheus_redis_exporter_password }} +{% endif %} diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 401e8a9..bdd5ef3 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -149,6 +149,7 @@ scrape_configs: {% endif %} {% if prometheus_varnish_exporter_targets is defined %} + # Varnish exporter # - job_name: varnish scrape_interval: 30s scrape_timeout: 10s @@ -204,3 +205,14 @@ scrape_configs: {% endif %} {% endif %} +{% if prometheus_redis_exporter_targets is defined %} + # Redis exporter # + - job_name: redis + scrape_interval: 30s + scrape_timeout: 10s + static_configs: + - targets: +{% for target in prometheus_redis_exporter_targets %} + - {{ target }}:9121 +{% endfor %} +{% endif %} diff --git a/templates/systemd/prometheus-redis-exporter.service.j2 b/templates/systemd/prometheus-redis-exporter.service.j2 index d74df38..7a1245b 100644 --- a/templates/systemd/prometheus-redis-exporter.service.j2 +++ b/templates/systemd/prometheus-redis-exporter.service.j2 @@ -1,10 +1,11 @@ [Unit] Description=Prometheus Redis Exporter After=network.target - + [Service] Type=simple ExecStart=/usr/local/bin/prometheus-redis-exporter - +EnvironmentFile=/etc/default/prometheus-redis-exporter + [Install] WantedBy=multi-user.target