Files
ansible-config/playbooks/monitoring/check_grafana.yml

48 lines
1.6 KiB
YAML
Raw Permalink Normal View History

---
- name: Check Grafana installation status
hosts: grafana
become: yes
tasks:
- name: Check Grafana service
systemd:
name: grafana
register: service_status
- name: Check if Grafana is listening on port
wait_for:
port: 3000
host: 127.0.0.1
timeout: 10
state: started
register: port_status
- name: Check Grafana API health
uri:
url: "http://localhost:3000/api/health"
method: GET
status_code: 200
timeout: 10
register: api_status
ignore_errors: yes
- name: Get Grafana version
command: /usr/local/bin/grafana-server --version
register: version_info
changed_when: false
ignore_errors: yes
- name: Display Grafana status report
debug:
msg: |
📊 Статус Grafana на {{ inventory_hostname }}:
Служба: {{ "✅ Запущена" if service_status.status.ActiveState == "active" else "❌ Остановлена" }}
Порт 3000: {{ "✅ Открыт" if port_status.state == "started" else "❌ Закрыт" }}
API: {{ "✅ Доступен (HTTP " ~ api_status.status ~ ")" if api_status.status == 200 else "❌ Недоступен" }}
{% if version_info is succeeded %}
Версия: {{ version_info.stdout_lines[-1] | regex_search('Version ([0-9.]+)') | default('Неизвестна') }}
{% else %}
Версия: Не удалось определить
{% endif %}