add varnish exporter

This commit is contained in:
Camille Prugnard 2021-10-08 15:22:59 +02:00
parent e01e571906
commit 4c9be50c29
6 changed files with 90 additions and 24 deletions

View File

@ -13,7 +13,7 @@ Role variables
-------------- --------------
| Variable | Type | Choices | Default | Comment | | Variable | Type | Choices | Default | Comment |
|----------------------------------------------|---------|------------------------------------------------------------------|-------------|-----------------| |----------------------------------------------|---------|----------------------------------------------------------------------------|-------------|-----------------|
| prometheus_server_enable | string | true / false | | | | prometheus_server_enable | string | true / false | | |
| prometheus_server_version | string | | latest | | | prometheus_server_version | string | | latest | |
| prometheus_server_monitor | string | | | | | prometheus_server_monitor | string | | | |
@ -22,7 +22,7 @@ Role variables
| prometheus_server_job_name | string | | prometheus | | | prometheus_server_job_name | string | | prometheus | |
| prometheus_server_scrape_interval | string | | 5 | | | prometheus_server_scrape_interval | string | | 5 | |
| prometheus_server_scrape_timeout | string | | 5 | | | prometheus_server_scrape_timeout | string | | 5 | |
| prometheus_exporter_packages | list | node / mysqld / postgresql / mongodb / phpfpm / apache / haproxy | | | | prometheus_exporter_packages | list | node / mysqld / postgresql / mongodb / phpfpm / apache / haproxy / varnish | | |
| prometheus_node_exporter_targets | list | | | | | prometheus_node_exporter_targets | list | | | |
| prometheus_mysqld_exporter_targets | list | | | | | prometheus_mysqld_exporter_targets | list | | | |
| prometheus_mongodb_exporter_targets | list | | | | | prometheus_mongodb_exporter_targets | list | | | |

View File

@ -46,3 +46,10 @@
state: restarted state: restarted
enabled: yes enabled: yes
tags: ['prometheus'] tags: ['prometheus']
- name: 'prometheus | varnish exporter | restart service'
systemd:
name: prometheus-varnish-exporter.service
state: restarted
enabled: yes
tags: ['prometheus']

View File

@ -39,3 +39,8 @@
include_tasks: 'apache_exporter.yml' include_tasks: 'apache_exporter.yml'
when: when:
- "'apache' in prometheus_exporter_packages" - "'apache' in prometheus_exporter_packages"
- name: 'prometheus | Varnish exporter'
include_tasks: 'varnish_exporter.yml'
when:
- "'varnish' in prometheus_exporter_packages"

View File

@ -0,0 +1,43 @@
---
- name: 'prometheus | 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: 'prometheus | varnish exporter | download'
get_url:
url: https://github.com/jonnenauha/prometheus_varnish_exporter/releases/download/v{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}/varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64.tar.gz
dest: /tmp
- name: 'prometheus | varnish exporter | unarchive'
unarchive:
remote_src: yes
src: /tmp/varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64.tar.gz
dest: /tmp
- name: 'prometheus | varnish exporter | move to /usr/local/bin'
copy:
src: /tmp/varnish_exporter-{{ prometheus_varnish_exporter_version|default(prometheus_varnish_exporter_latest_version.stdout) }}.linux-amd64/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: 'prometheus | 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: 'prometheus | varnish exporter | configure systemd to use service'
systemd:
daemon_reload: yes
enabled: yes
name: prometheus-varnish-exporter.service

View File

@ -107,3 +107,14 @@ scrape_configs:
- {{ target }}:8404 - {{ target }}:8404
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if prometheus_varnish_exporter_targets is defined %}
- job_name: varnish
scrape_interval: 30s
scrape_timeout: 10s
static_configs:
- targets:
{% for target in prometheus_varnish_exporter_targets %}
- {{ target }}:9131
{% endfor %}
{% endif %}