| {%- from "telegraf/map.jinja" import agent with context -%} |
| {%- if agent.output is defined %} |
| {%- if agent.output.prometheus_client is defined %} |
| {%- if agent.output.prometheus_client.bind.address == '0.0.0.0' %} |
| {%- set fqdn_ip4_addresses = [] %} |
| {%- for addr in grains['fqdn_ip4'] %} |
| {%- if not addr.startswith('127.') %} |
| {%- do fqdn_ip4_addresses.append(addr) %} |
| {%- endif %} |
| {%- endfor %} |
| {%- set address = fqdn_ip4_addresses[0] %} |
| {%- else %} |
| {%- set address = agent.output.prometheus_client.bind.address %} |
| {%- endif %} |
| {%- endif %} |
| {%- endif %} |
| |
| {%- if address is defined %} |
| server: |
| target: |
| static: |
| telegraf: |
| endpoint: |
| - address: {{ address }} |
| port: {{ agent.output.prometheus_client.bind.port }} |
| relabel_configs: |
| - regex: {{ address }}:{{ agent.output.prometheus_client.bind.port }} |
| replacement: {{ grains['host'] }} |
| source_labels: "__address__" |
| target_label: "host" |
| honor_labels: true |
| {%- endif %} |