promtail: Move hard-coded config to prometheus_agent.agents.promtail.config inventory key

This commit is contained in:
Julian Rother 2024-11-23 01:09:47 +01:00
parent 71c00d0cce
commit 7d0415ecf6
No known key found for this signature in database
GPG key ID: 8F9B6AE9BAAE4899
2 changed files with 48 additions and 46 deletions

View file

@ -43,6 +43,49 @@ prometheus_agent:
jobs: {} jobs: {}
promtail: promtail:
enable: False 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: snmp:
enable: False enable: False
mib_path: /usr/share/snmp/mibs mib_path: /usr/share/snmp/mibs

View file

@ -1,49 +1,8 @@
server: {% if 'clients' not in prometheus_agent.agents.promtail.config %}
disable: true {% set tmp = prometheus_agent.agents.promtail.config.setdefault('clients', []) %}
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /var/lib/promtail/positions.yaml
clients:
{% for i in prometheus_agent.scrapers if prometheus_agent.scrapers[i].get("loki") %} {% 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'] ) %} {% 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 %} {% endfor %}
{% endif %}
scrape_configs: {{ prometheus_agent.agents.promtail.config|to_nice_yaml(indent=2) }}
- 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