From e1539aee0eb5823b84e795be234361a412a4d6bf Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Wed, 28 Jun 2017 09:28:56 +0200 Subject: [PATCH] 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 --- prometheus/files/prometheus.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/prometheus/files/prometheus.yml b/prometheus/files/prometheus.yml index c8dd17b..e7652f3 100644 --- a/prometheus/files/prometheus.yml +++ b/prometheus/files/prometheus.yml @@ -47,9 +47,15 @@ rule_files: {%- if static_target[job_name]['endpoint'] is not defined %} {%- do static_target[job_name].update({'endpoint': []}) %} {%- 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', []) %} {%- do static_target[job_name]['endpoint'].append(target) %} {%- endfor %} + {%- for label in job.get('metric_relabel', []) %} + {%- do static_target[job_name]['metric_relabel'].append(label) %} + {%- endfor %} {%- endfor %} {%- endfor %} @@ -71,6 +77,22 @@ scrape_configs: {%- endif %} static_configs: - 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 %} {%- endfor %}