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 %}