From f02c1270fe19458f2d3f00200b1f2225796768fb Mon Sep 17 00:00:00 2001 From: Camille Prugnard Date: Fri, 8 Oct 2021 10:23:56 +0200 Subject: [PATCH] add php exporter --- README.md | 44 ++++++++-------- defaults/main.yml | 2 + handlers/main.yml | 7 +++ tasks/apache_exporter.yml | 51 +++++++++++++++++++ tasks/main.yml | 5 ++ .../prometheus-apache-exporter.service.j2 | 10 ++++ 6 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 tasks/apache_exporter.yml create mode 100644 templates/systemd/prometheus-apache-exporter.service.j2 diff --git a/README.md b/README.md index ab11c39..40c5838 100644 --- a/README.md +++ b/README.md @@ -12,28 +12,28 @@ 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 | | | -| 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 | | | +| 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 | | Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 37bf178..3b33404 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,8 @@ --- awh_services_docker_pull: "no" +prometheus_apache_port: 8080 + prometheus_exporter_packages: [] prometheus_nodes_ip: diff --git a/handlers/main.yml b/handlers/main.yml index 66f0fd7..3c12cb6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -39,3 +39,10 @@ state: restarted enabled: yes tags: ['prometheus'] + +- name: 'prometheus | apache exporter | restart service' + systemd: + name: prometheus-apache-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] diff --git a/tasks/apache_exporter.yml b/tasks/apache_exporter.yml new file mode 100644 index 0000000..f9890a5 --- /dev/null +++ b/tasks/apache_exporter.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index c25b758..906ad34 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,3 +34,8 @@ include_tasks: 'phpfpm_exporter.yml' when: - "'phpfpm' in prometheus_exporter_packages" + +- name: 'prometheus | Apache exporter' + include_tasks: 'apache_exporter.yml' + when: + - "'apache' in prometheus_exporter_packages" diff --git a/templates/systemd/prometheus-apache-exporter.service.j2 b/templates/systemd/prometheus-apache-exporter.service.j2 new file mode 100644 index 0000000..c525d0d --- /dev/null +++ b/templates/systemd/prometheus-apache-exporter.service.j2 @@ -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