diff --git a/defaults/main.yml b/defaults/main.yml index a00ec54..82d3bd5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -43,6 +43,49 @@ prometheus_agent: jobs: {} promtail: enable: False + config: + server: + disable: true + http_listen_port: 9080 + grpc_listen_port: 0 + positions: + filename: /var/lib/promtail/positions.yaml + # clients is generated based on prometheus_agent.scrapers + scrape_configs: + - job_name: system + static_configs: + - targets: + - localhost + labels: + job: varlogs + __path__: /var/log/*log + - job_name: journal + journal: + max_age: 12h + labels: + job: systemd-journal + relabel_configs: + - source_labels: ['__journal__systemd_unit'] + target_label: 'unit' + - source_labels: ['__journal_priority_keyword'] + target_label: 'level' + pipeline_stages: + - structured_metadata: + level: + - job_name: nginx + static_configs: + - targets: + - localhost + labels: + job: nginx + __path__: /var/log/nginx/access-promtail.log + - job_name: postfix-bounces + static_configs: + - targets: + - localhost + labels: + job: postfix-bounces + __path__: /var/log/mailman3/bounce.log snmp: enable: False mib_path: /usr/share/snmp/mibs diff --git a/templates/promtail.yml.j2 b/templates/promtail.yml.j2 index 30c4240..28e4fcc 100644 --- a/templates/promtail.yml.j2 +++ b/templates/promtail.yml.j2 @@ -1,49 +1,8 @@ -server: - disable: true - http_listen_port: 9080 - grpc_listen_port: 0 - -positions: - filename: /var/lib/promtail/positions.yaml - -clients: +{% if 'clients' not in prometheus_agent.agents.promtail.config %} +{% set tmp = prometheus_agent.agents.promtail.config.setdefault('clients', []) %} {% for i in prometheus_agent.scrapers if prometheus_agent.scrapers[i].get("loki") %} {% set lokiconfig = {}|combine({ "external_labels": merged_prometheus_labels|combine( {"instance": inventory_hostname} ) }, prometheus_agent.scrapers[i]['loki'] ) %} - - {{ lokiconfig|to_json }} +{% set tmp = prometheus_agent.agents.promtail.config.clients.append(lokiconfig) %} {% endfor %} - -scrape_configs: -- job_name: system - static_configs: - - targets: - - localhost - labels: - job: varlogs - __path__: /var/log/*log -- job_name: journal - journal: - max_age: 12h - labels: - job: systemd-journal - relabel_configs: - - source_labels: ['__journal__systemd_unit'] - target_label: 'unit' - - source_labels: ['__journal_priority_keyword'] - target_label: 'level' - pipeline_stages: - - structured_metadata: - level: -- job_name: nginx - static_configs: - - targets: - - localhost - labels: - job: nginx - __path__: /var/log/nginx/access-promtail.log -- job_name: postfix-bounces - static_configs: - - targets: - - localhost - labels: - job: postfix-bounces - __path__: /var/log/mailman3/bounce.log +{% endif %} +{{ prometheus_agent.agents.promtail.config|to_nice_yaml(indent=2) }}