about summary refs log tree commit diff
path: root/bundles/prometheus/items.py
blob: 99aecbc0edbd7fc3f4b449bfa754617d2dfae926 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from sys import exit
from os.path import join

actions = {
    "reload_prometheus": {
        "command": "podman kill -s HUP prometheus-prom",
        "triggered": True,
    },
    "reload_alertmanager": {
        "command": "podman kill -s HUP prometheus-alert",
        "triggered": True,
    },
}

files = {
    "/etc/deployments/prometheus/kube.yaml": {
        "content_type": "mako",
        "context": node.metadata.get("containers")["prometheus"],
        "triggers": {"svc_s6rc:prometheus:restart"},
    },
    "/etc/prometheus/prometheus.yml": {
        "content_type": "text",
        "triggers": {"action:reload_prometheus"},
    },
    "/etc/prometheus/rules/generic.yml": {
        "source": "rules.yml",
        "triggers": {"action:reload_prometheus"},
    },
    "/etc/prometheus/alertmanager.yml": {
        "content_type": "mako",
        "triggers": {"action:reload_alertmanager"},
    },
}

repo.libs.gen.add_files_recursive(
    files,
    join(repo.path, "bundles", "prometheus", "files", "consoles"),
    target_root="/etc/prometheus",
    files_root=join(repo.path, "bundles", "prometheus", "files"),
)
repo.libs.gen.add_files_recursive(
    files,
    join(repo.path, "bundles", "prometheus", "files", "console_libraries"),
    target_root="/etc/prometheus",
    files_root=join(repo.path, "bundles", "prometheus", "files"),
)
repo.libs.gen.add_files_recursive(
    files,
    join(repo.path, "bundles", "prometheus", "files", "console_assets"),
    target_root="/etc/prometheus",
    files_root=join(repo.path, "bundles", "prometheus", "files"),
)

directories = {
    "/etc/prometheus/services": {"purge": True},
    "/etc/prometheus/rules": {"purge": True},
    "/etc/prometheus/consoles": {"purge": True},
    "/etc/prometheus/console_libraries": {"purge": True},
    "/etc/prometheus/console_assets": {"purge": True},
}

# NOTE: services that want to have their metrics scraped need to expose them
#       under traefik:4000/metrics/<svc> and set metadata.metrics.<svc>
for node in repo.nodes:
    for job_name, _ in node.metadata.get("metrics", {}).items():
        files[f"/etc/prometheus/services/{node.hostname}.{job_name}.json"] = {
            "content_type": "mako",
            "source": "service.json",
            "context": {
                "job_name": job_name,
                "hostname": node.hostname,
            },
        }