Passa al contenuto principale

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:

  1. Crea infra/roles/prometheus/templates/scrape.d/<service>.yml.j2:

    - job_name: <service>
    metrics_path: /metrics
    scheme: http
    static_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>
  2. Aggiungi l'include esplicito in infra/roles/prometheus/templates/prometheus.yml.j2 sotto scrape_configs:

    {% include 'scrape.d/<service>.yml.j2' %}
  3. Verifica e applica:

    ansible-playbook --syntax-check -i infra/inventory/staging.yml infra/playbooks/deploy_management.yml
    ansible-playbook -i infra/inventory/staging.yml infra/playbooks/deploy_management.yml \
    --vault-password-file ~/.akira-vault-pass.txt \
    --tags prometheus --check --diff
    ansible-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/.