Fix exporters configuration to be generic

Change-Id: If5cf3662f96311a5f37055c0f62934ba5407a978
This commit is contained in:
Olivier Bourdon 2017-07-10 10:01:46 +02:00
parent 3abe6788d0
commit 31bfa9d94c
6 changed files with 54 additions and 10 deletions

View file

@ -6,9 +6,10 @@ parameters:
prometheus: prometheus:
exporters: exporters:
jmx: jmx:
enabled: true
packages: packages:
- jmx-exporter - jmx-exporter
bind: services:
address: 0.0.0.0 cassandra:
port: ${_param:prometheus_exporter_jmx_port} bind:
address: 0.0.0.0
port: ${_param:prometheus_exporter_jmx_port}

View file

@ -6,9 +6,10 @@ parameters:
prometheus: prometheus:
exporters: exporters:
libvirt: libvirt:
enabled: true
packages: packages:
- libvirt-exporter - libvirt-exporter
bind: services:
address: 0.0.0.0 qemu:
port: ${_param:prometheus_exporter_libvirt_port} bind:
address: 0.0.0.0
port: ${_param:prometheus_exporter_libvirt_port}

View file

@ -0,0 +1,42 @@
{%- if exporters is defined %}
{%- if new_exporters_cfg is defined %}
{%- do salt['defaults.merge'](exporters, new_exporters_cfg['exporters']) %}
{%- endif %}
{%- set host = grains.get('host', "") %}
{%- set host_ip_address = grains['fqdn_ip4'][0] %}
{%- load_yaml as svc_configs %}
{%- for exporter, parameters in exporters.iteritems() %}
{%- if parameters.get('enabled', False) %}
{%- for svc, svc_parameters in parameters.get('services', {}).iteritems() %}
{%- if svc_parameters.get('enabled', False) %}
{%- if svc_parameters.bind is defined %}
{%- if svc_parameters.bind.get('address', '0.0.0.0') == '0.0.0.0' %}
{%- set address = host_ip_address %}
{%- else %}
{%- set address = svc_parameters.bind.address %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- if address is defined and svc_parameters.bind.port is defined %}
{{ exporter }}_{{ svc }}_exporter:
endpoint:
- address: {{ address }}
port: {{ svc_parameters.bind.port }}
{%- if host is defined and host|length > 0 %}
metric_relabel:
- regex: {{ address }}:{{ svc_parameters.bind.port }}
replacement: {{ host }}
source_labels: "instance"
target_label: "host"
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endload %}
{%- if svc_configs %}
target:
static:
{{ svc_configs|yaml(False)|indent(6, True) }}
{%- endif %}
{%- endif %}

View file

@ -1,5 +1,4 @@
{% from "prometheus/map.jinja" import exporters with context %} {% from "prometheus/map.jinja" import exporters with context %}
{%- for exporter, parameters in exporters.iteritems() %} {%- for exporter, parameters in exporters.iteritems() %}
{%- if parameters.get('enabled', False) %} {%- if parameters.get('enabled', False) %}
{%- if parameters.get('packages', False) %} {%- if parameters.get('packages', False) %}

View file

@ -16,3 +16,4 @@
'default': { 'default': {
}, },
}, merge=salt['pillar.get']('prometheus:exporters')) %} }, merge=salt['pillar.get']('prometheus:exporters')) %}
{%- do salt['defaults.merge'](exporters, grains.get('prometheus', {}).get('exporters', {})) %}

View file

@ -1,6 +1,6 @@
grain: grain:
{%- if pillar.get('prometheus', {}).get('collector') %} {%- if pillar.get('prometheus', {}).get('collector') %}
{%- from "prometheus/map.jinja" import server as prometheus_server with context %} {%- from "prometheus/map.jinja" import exporters,server as prometheus_server with context %}
prometheus: prometheus:
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': {}, 'target': {}}}} %} {%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': {}, 'target': {}}}} %}
{%- for service_name, service in pillar.items() %} {%- for service_name, service in pillar.items() %}