Aggiungere nuovo scrape target Prometheus
Prometheus viene configurato dal ruolo Ansible
infra/roles/prometheus. I job di scrape vivono in file separati sotto
infra/roles/prometheus/templates/scrape.d/ per ridurre i conflitti tra
task paralleli.
Per aggiungere il monitoring di un nuovo servizio:
-
Crea
infra/roles/prometheus/templates/scrape.d/<service>.yml.j2:- job_name: <service>metrics_path: /metricsscheme: httpstatic_configs:- targets:{% for h in groups['<service>_nodes'] | default([]) %}- "{{ hostvars[h].ansible_tailscale_ipv4 | default(hostvars[h].tailscale_ip | default(hostvars[h].ansible_host | default(h))) }}:<port>"{% endfor %}labels:cluster: "{{ app_name | default('akira') }}-{{ app_env | default('staging') }}"role: <service>service: <service> -
Aggiungi l'include esplicito in
infra/roles/prometheus/templates/prometheus.yml.j2sottoscrape_configs:{% include 'scrape.d/<service>.yml.j2' %} -
Verifica e applica:
ansible-playbook --syntax-check -i infra/inventory/staging.yml infra/playbooks/deploy_management.ymlansible-playbook -i infra/inventory/staging.yml infra/playbooks/deploy_management.yml \--vault-password-file ~/.akira-vault-pass.txt \--tags prometheus --check --diffansible-playbook -i infra/inventory/staging.yml infra/playbooks/deploy_management.yml \--vault-password-file ~/.akira-vault-pass.txt \--tags prometheus
Il pattern atteso e' un file per servizio piu' una riga di include nel
template master. Task paralleli che aggiungono servizi diversi devono
toccare file diversi sotto scrape.d/.