feat(monitoring): цели Prometheus из inventory и хосты в Grafana через up
ansible-core-mon / deploy (push) Successful in 26s
ansible-core-net / deploy (push) Successful in 43s
ansible-core-secrets / deploy (push) Successful in 15s
ansible-ger-nod-02 / deploy (push) Successful in 55s
ansible-opnsense / deploy (push) Successful in 5s
ansible-rus-central / deploy (push) Successful in 59s

Список scrape строится из inventory, дашборд показывает все цели, не только с успешным node_exporter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
karpenokandCursor committed 2026-11-12 12:50:23 +07:00
1 parent 4316f2c68e
commit 408dfd09c3
6 files changed
+79 -26

No files matched your search

@@ -20,6 +20,34 @@
- { path: "{{ monitoring_dir }}/ntfy_data", owner: "root", group: "root", mode: "0777" }
- { path: "{{ monitoring_dir }}/alertmanager-ntfy", owner: "root", group: "root", mode: "0755" }
- name: Сбросить список целей scrape node-exporter
ansible.builtin.set_fact:
monitoring_scrape_targets: []
- name: Собрать цели scrape node-exporter из inventory
ansible.builtin.set_fact:
monitoring_scrape_targets: "{{ monitoring_scrape_targets + [target] }}"
vars:
target:
name: "{{ item }}"
address: "{{ hostvars[item].monitoring_scrape_address | default(hostvars[item].ansible_host) }}"
port: "{{ hostvars[item].monitoring_node_exporter_port | default(monitoring_node_exporter_port) }}"
env: "{{ hostvars[item].monitoring_env | default(monitoring_env_label) }}"
loop: "{{ groups['all'] | sort }}"
when:
- item not in monitoring_scrape_exclude_hosts
- hostvars[item].monitoring_scrape_enabled | default(true) | bool
- name: Проверить, что в Prometheus есть хотя бы одна цель node-exporter
ansible.builtin.assert:
that:
- monitoring_scrape_targets | length > 0
fail_msg: "Нет целей scrape: проверьте inventory и monitoring_scrape_exclude_hosts."
- name: Показать цели scrape node-exporter
ansible.builtin.debug:
msg: "{{ monitoring_scrape_targets | map(attribute='name') | list | sort }}"
- name: Установить конфигурацию Prometheus
ansible.builtin.template:
src: prometheus.yml.j2
@@ -27,6 +55,7 @@
owner: root
group: root
mode: "0644"
notify: Reload Prometheus configuration
- name: Установить правила алертов Prometheus
ansible.builtin.copy:
@@ -35,6 +64,7 @@
owner: root
group: root
mode: "0644"
notify: Reload Prometheus configuration
- name: Установить конфигурацию Alertmanager
ansible.builtin.template:
@@ -75,6 +105,7 @@
owner: root
group: root
mode: "0644"
notify: Restart Grafana
- name: Установить compose.yaml для стека мониторинга
ansible.builtin.template: