Mercurial > code > home > repos > victoriametrics
diff next/scrape_job.py @ 64:def1aa2bfa3f
more targets polish. reorg code into next/
author | drewp@bigasterisk.com |
---|---|
date | Thu, 02 May 2024 23:06:31 -0700 |
parents | 8134cd480817 |
children |
line wrap: on
line diff
--- a/next/scrape_job.py Thu May 02 23:05:14 2024 -0700 +++ b/next/scrape_job.py Thu May 02 23:06:31 2024 -0700 @@ -2,14 +2,13 @@ from pathlib import Path import subprocess +class FromName: + pass -def jobConfig(name, targets, scrape_interval=None, ping_job=False, metrics_path=None, params=None): +def jobConfig(name, targets, scrape_interval=None, ping_job=False, metrics_path=None, params=None, https=False): """one scrape job config""" ret = { "job_name": name, - "static_configs": [{ - "targets": targets, - }], "relabel_configs": [ { "target_label": "namespace", @@ -21,9 +20,21 @@ }, ] } + + if targets is FromName: + targets = [name] + + if targets: + ret["static_configs"] = [{ + "targets": targets, + }] if metrics_path: - ret['metrics_path'] = metrics_path + ret.setdefault('relabel_configs', []).append({ + "action": "replace", + "target_label": "__metrics_path__", + "replacement": metrics_path, + }) if scrape_interval: ret['scrape_interval'] = scrape_interval @@ -49,6 +60,11 @@ }, ] + if https: + ret['scheme'] = 'https' + ret["tls_config"] = {"ca_file": "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"} + ret["bearer_token_file"] = "/var/run/secrets/kubernetes.io/serviceaccount/token" + return ret @@ -59,12 +75,10 @@ yield name -def scrape_deployments(deploy_doesnt_serve_metrics, forever_jobs): +def scrape_deployments(skip_names): ret = [] for name in current_deployments(): - if name in deploy_doesnt_serve_metrics: - continue - if name in [j['job_name'] for j in forever_jobs]: + if name in skip_names: continue targets = [name] ret.append(jobConfig(name=name, targets=targets)) @@ -84,5 +98,5 @@ "scrape_interval": "1m", "scrape_timeout": "10s" }, - "scrape_config_files": filenames_written, + "scrape_config_files": sorted(filenames_written), }, indent=2))