Add prometheus metrics to alloy
This commit is contained in:
parent
616788c5ea
commit
5ad3e9bfe2
8 changed files with 174 additions and 19 deletions
44
playbooks/filter_plugins/alloy.py
Normal file
44
playbooks/filter_plugins/alloy.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
def transfer_optional_param(source, target, name, target_name=None):
|
||||
if param := source.get(name):
|
||||
target[target_name or name] = param
|
||||
|
||||
class FilterModule(object):
|
||||
def filters(self):
|
||||
return {
|
||||
'services_to_alloy': self.services_to_alloy,
|
||||
}
|
||||
|
||||
def services_to_alloy(self, services):
|
||||
result = []
|
||||
|
||||
for name, service in services.items():
|
||||
if not bool(service.get("host")):
|
||||
continue
|
||||
|
||||
if targets := service.get("metrics") or []:
|
||||
job = {
|
||||
"name": name,
|
||||
"targets": [],
|
||||
"scrape_interval": "60s",
|
||||
}
|
||||
|
||||
for target in targets:
|
||||
|
||||
address = target.get("address") or service["dns"][0]['domain']
|
||||
|
||||
transfer_optional_param(target, job, "interval", "scrape_interval")
|
||||
|
||||
new_target = {
|
||||
"address": address,
|
||||
"path": target["path"],
|
||||
"instance": name
|
||||
}
|
||||
|
||||
transfer_optional_param(target, new_target, "instance")
|
||||
transfer_optional_param(target, new_target, "job")
|
||||
|
||||
job["targets"].append(new_target)
|
||||
|
||||
result.append(job)
|
||||
|
||||
return result
|
Loading…
Add table
Add a link
Reference in a new issue