Set the python script to read and push also targets cofiguration
This commit is contained in:
parent
91c08d713f
commit
3e6582b326
@ -17,7 +17,8 @@ OUTPUT_FILE = os.path.join(
|
||||
)
|
||||
|
||||
os.makedirs(TMP_DIR, exist_ok=True)
|
||||
|
||||
yaml = YAML()
|
||||
yaml.default_flow_style = False
|
||||
|
||||
def collect_targets():
|
||||
jobs = {}
|
||||
@ -29,29 +30,33 @@ def collect_targets():
|
||||
|
||||
for path in Path(repo_path, "manifests").glob("*/monitoring.yaml"):
|
||||
with open(path) as f:
|
||||
data = YAML().load(f)
|
||||
data = yaml.load(f)
|
||||
|
||||
if data.get("enabled") and "targets" in data:
|
||||
if name not in jobs:
|
||||
jobs[name] = []
|
||||
jobs[name].extend(data["targets"])
|
||||
if data.get("enabled"):
|
||||
job = {
|
||||
"job_name": path.parent.name, # app name
|
||||
"static_configs": [{"targets": data.get("targets", [])}]
|
||||
}
|
||||
|
||||
if "metrics_path" in data:
|
||||
job["metrics_path"] = data["metrics_path"]
|
||||
if "scheme" in data:
|
||||
job["scheme"] = data["scheme"]
|
||||
if "basic_auth" in data:
|
||||
job["basic_auth"] = data["basic_auth"]
|
||||
|
||||
jobs.setdefault(name, []).append(job)
|
||||
|
||||
return jobs
|
||||
|
||||
|
||||
def write_scrape_config(jobs, output_file):
|
||||
result = []
|
||||
for repo, targets in jobs.items():
|
||||
result.append({
|
||||
"job_name": repo,
|
||||
"static_configs": [{"targets": targets}]
|
||||
})
|
||||
job_list = []
|
||||
for repo_jobs in jobs.values():
|
||||
job_list.extend(repo_jobs)
|
||||
|
||||
# השתמש ב־StringIO כדי לבנות טקסט יפה כ־string
|
||||
stream = StringIO()
|
||||
yaml_writer = YAML()
|
||||
yaml_writer.default_flow_style = False
|
||||
yaml_writer.dump(result, stream)
|
||||
yaml.dump(job_list, stream)
|
||||
scrape_yaml = "# This content will be auto-updated by the pipeline\n" + stream.getvalue()
|
||||
|
||||
secret = {
|
||||
@ -72,7 +77,7 @@ def write_scrape_config(jobs, output_file):
|
||||
|
||||
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
||||
with open(output_file, "w") as f:
|
||||
yaml_writer.dump(secret, f)
|
||||
yaml.dump(secret, f)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user