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