Fix exporters configuration to be generic
Change-Id: If5cf3662f96311a5f37055c0f62934ba5407a978
This commit is contained in:
parent
3abe6788d0
commit
31bfa9d94c
6 changed files with 54 additions and 10 deletions
|
@ -6,9 +6,10 @@ parameters:
|
|||
prometheus:
|
||||
exporters:
|
||||
jmx:
|
||||
enabled: true
|
||||
packages:
|
||||
- jmx-exporter
|
||||
bind:
|
||||
address: 0.0.0.0
|
||||
port: ${_param:prometheus_exporter_jmx_port}
|
||||
services:
|
||||
cassandra:
|
||||
bind:
|
||||
address: 0.0.0.0
|
||||
port: ${_param:prometheus_exporter_jmx_port}
|
||||
|
|
|
@ -6,9 +6,10 @@ parameters:
|
|||
prometheus:
|
||||
exporters:
|
||||
libvirt:
|
||||
enabled: true
|
||||
packages:
|
||||
- libvirt-exporter
|
||||
bind:
|
||||
address: 0.0.0.0
|
||||
port: ${_param:prometheus_exporter_libvirt_port}
|
||||
services:
|
||||
qemu:
|
||||
bind:
|
||||
address: 0.0.0.0
|
||||
port: ${_param:prometheus_exporter_libvirt_port}
|
||||
|
|
42
prometheus/_exporters_config.sls
Normal file
42
prometheus/_exporters_config.sls
Normal 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 %}
|
|
@ -1,5 +1,4 @@
|
|||
{% from "prometheus/map.jinja" import exporters with context %}
|
||||
|
||||
{%- for exporter, parameters in exporters.iteritems() %}
|
||||
{%- if parameters.get('enabled', False) %}
|
||||
{%- if parameters.get('packages', False) %}
|
||||
|
|
|
@ -16,3 +16,4 @@
|
|||
'default': {
|
||||
},
|
||||
}, merge=salt['pillar.get']('prometheus:exporters')) %}
|
||||
{%- do salt['defaults.merge'](exporters, grains.get('prometheus', {}).get('exporters', {})) %}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
grain:
|
||||
{%- 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:
|
||||
{%- set service_grains = {'prometheus': {'server': {'alert': {}, 'recording': {}, 'target': {}}}} %}
|
||||
{%- for service_name, service in pillar.items() %}
|
||||
|
|
Loading…
Reference in a new issue