Add Prometheus metrics relabel configuration for exporters

Tested succesfully with the following test cases:
            source_labels: instance
            source_labels: instance,__name__,test
            source_labels: [instance,__name__,test]
            source_labels:
              - instance
              - __name__
              - test

Change-Id: I9750bb0a4204335dd202cc4020445e850824c497
Depends-On: I2f85fe2f9cc67d2d03d5e8dad5ac0b74e82b0fcc
This commit is contained in:
Olivier Bourdon 2017-06-28 09:28:56 +02:00
parent 9a986bebf7
commit e1539aee0e

View file

@ -47,9 +47,15 @@ rule_files:
{%- if static_target[job_name]['endpoint'] is not defined %} {%- if static_target[job_name]['endpoint'] is not defined %}
{%- do static_target[job_name].update({'endpoint': []}) %} {%- do static_target[job_name].update({'endpoint': []}) %}
{%- endif %} {%- endif %}
{%- if static_target[job_name]['metric_relabel'] is not defined %}
{%- do static_target[job_name].update({'metric_relabel': []}) %}
{%- endif %}
{%- for target in job.get('endpoint', []) %} {%- for target in job.get('endpoint', []) %}
{%- do static_target[job_name]['endpoint'].append(target) %} {%- do static_target[job_name]['endpoint'].append(target) %}
{%- endfor %} {%- endfor %}
{%- for label in job.get('metric_relabel', []) %}
{%- do static_target[job_name]['metric_relabel'].append(label) %}
{%- endfor %}
{%- endfor %} {%- endfor %}
{%- endfor %} {%- endfor %}
@ -71,6 +77,22 @@ scrape_configs:
{%- endif %} {%- endif %}
static_configs: static_configs:
- targets: [{{ nodes | join(',') }}] - targets: [{{ nodes | join(',') }}]
{%- if job.get('metric_relabel') %}
metric_relabel_configs:
{%- for label in job.get('metric_relabel', []) %}
{%- if label.source_labels is string %}
{%- set label_list = label.source_labels.split(',') %}
{%- elif label.source_labels is list %}
{%- set label_list = label.source_labels %}
{%- endif %}
{%- if label_list is defined %}
- source_labels: {{ label_list }}
regex: "{{ label.regex }}"
target_label: "{{ label.target_label }}"
replacement: {{ label.replacement }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}