add php exporter

This commit is contained in:
Camille Prugnard 2021-10-08 10:23:56 +02:00
parent bca9798942
commit f02c1270fe
6 changed files with 97 additions and 22 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 | | | | prometheus_exporter_packages | list | node / mysqld / postgresql / mongodb / phpfpm / apache | | |
| 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

@ -1,6 +1,8 @@
--- ---
awh_services_docker_pull: "no" awh_services_docker_pull: "no"
prometheus_apache_port: 8080
prometheus_exporter_packages: [] prometheus_exporter_packages: []
prometheus_nodes_ip: prometheus_nodes_ip:

View File

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

51
tasks/apache_exporter.yml Normal file
View File

@ -0,0 +1,51 @@
---
- name: 'prometheus | 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: 'prometheus | 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: 'prometheus | 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: 'prometheus | 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: 'prometheus | apache exporter | install startup script'
template:
src: scripts/prometheus-apache-exporter-script.sh.j2
dest: /usr/local/bin/prometheus-apache-exporter-script.sh
owner: root
group: root
mode: 0600
- name: 'prometheus | 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

View File

@ -34,3 +34,8 @@
include_tasks: 'phpfpm_exporter.yml' include_tasks: 'phpfpm_exporter.yml'
when: when:
- "'phpfpm' in prometheus_exporter_packages" - "'phpfpm' in prometheus_exporter_packages"
- name: 'prometheus | Apache exporter'
include_tasks: 'apache_exporter.yml'
when:
- "'apache' in prometheus_exporter_packages"

View File

@ -0,0 +1,10 @@
[Unit]
Description=Prometheus Apache Exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/prometheus-apache-exporter --scrape_uri="http://localhost:{{ prometheus_apache_port }}/server-status/?auto"
[Install]
WantedBy=multi-user.target