Добавлена конфигурация мониторинга Nginx и финальные правки для app1
This commit is contained in:
65
playbooks/install-nginx-exporter.yml
Normal file
65
playbooks/install-nginx-exporter.yml
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
- name: Install nginx-prometheus-exporter on App1
|
||||
hosts: 192.168.0.110
|
||||
become: yes
|
||||
|
||||
tasks:
|
||||
- name: Download nginx-prometheus-exporter
|
||||
get_url:
|
||||
url: https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
|
||||
dest: /tmp/nginx-exporter.tar.gz
|
||||
|
||||
- name: Extract nginx-exporter
|
||||
unarchive:
|
||||
src: /tmp/nginx-exporter.tar.gz
|
||||
dest: /usr/local/bin/
|
||||
remote_src: yes
|
||||
creates: /usr/local/bin/nginx-prometheus-exporter
|
||||
|
||||
- name: Create systemd service
|
||||
copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=NGINX Prometheus Exporter
|
||||
After=network.target nginx.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/nginx-prometheus-exporter -nginx.scrape-uri=http://localhost:80/status
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
dest: /etc/systemd/system/nginx-exporter.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: Enable and start nginx-exporter
|
||||
systemd:
|
||||
name: nginx-exporter
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
- name: Test nginx-exporter
|
||||
uri:
|
||||
url: http://localhost:9113/metrics
|
||||
status_code: 200
|
||||
register: exporter_test
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Show test result
|
||||
debug:
|
||||
msg: "Nginx exporter test: {{ 'SUCCESS' if exporter_test.status == 200 else 'FAILED' }}"
|
||||
|
||||
- name: Verify metrics
|
||||
shell: |
|
||||
curl -s http://localhost:9113/metrics | grep -i nginx | head -5
|
||||
register: metrics_check
|
||||
changed_when: false
|
||||
|
||||
- name: Show metrics check
|
||||
debug:
|
||||
msg: "{{ metrics_check.stdout_lines }}"
|
||||
Reference in New Issue
Block a user