You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/roles/prometheus/filter_plugins/prometheus.py

55 lines
1.4 KiB
Python

from ansible.parsing.yaml.objects import AnsibleUnicode
class FilterModule:
def filters(self):
return {
"prometheus__convert_jobs": convert_jobs,
}
def convert_jobs(config):
for name, job in config.items():
config = {
"job_name": name,
"static_configs": [
{
"targets": job["targets"],
}
],
"params": job.get("params", {}),
}
if "path" in job:
config["metrics_path"] = job["path"]
if "timeout" in job:
config["scrape_timeout"] = job["timeout"]
if "address" in job:
try:
replacement = f"$1:{job['address']['port']}"
except Exception:
replacement = job["address"]
config["relabel_configs"] = [
{
"source_labels": ["__address__"],
"target_label": "__param_target",
},
{
"source_labels": ["__param_target"],
"target_label": "instance",
},
{
"source_labels": ["__param_target"],
"target_label": "__address__",
"replacement": replacement,
},
]
yield config