Merge pull request #150 from ryan4yin/p8s-scrape-configs

refactor: p8s scrape configs
This commit is contained in:
Ryan Yin
2024-07-31 21:41:19 +08:00
committed by GitHub
+30 -18
View File
@@ -1,4 +1,5 @@
{ {
lib,
config, config,
myvars, myvars,
... ...
@@ -45,23 +46,8 @@
# specifies a set of targets and parameters describing how to scrape metrics from them. # specifies a set of targets and parameters describing how to scrape metrics from them.
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config # https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
scrapeConfigs = [ scrapeConfigs =
# --- Hosts --- # [
{
job_name = "node-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# All my NixOS hosts.
targets =
map (addr: "${addr.ipv4}:9100")
(builtins.attrValues myvars.networking.hostsAddr);
labels.type = "node";
}
];
}
# --- Homelab Applications --- # # --- Homelab Applications --- #
{ {
@@ -73,6 +59,7 @@
targets = ["${myvars.networking.hostsAddr.suzi.ipv4}:9153"]; targets = ["${myvars.networking.hostsAddr.suzi.ipv4}:9153"];
labels.type = "app"; labels.type = "app";
labels.app = "dnsmasq"; labels.app = "dnsmasq";
labels.host = "suzi";
} }
]; ];
} }
@@ -86,6 +73,7 @@
targets = ["${myvars.networking.hostsAddr.aquamarine.ipv4}:9153"]; targets = ["${myvars.networking.hostsAddr.aquamarine.ipv4}:9153"];
labels.type = "app"; labels.type = "app";
labels.app = "v2ray"; labels.app = "v2ray";
labels.host = "aquamarine";
} }
]; ];
} }
@@ -98,11 +86,35 @@
{ {
targets = ["${myvars.networking.hostsAddr.aquamarine.ipv4}:10000"]; targets = ["${myvars.networking.hostsAddr.aquamarine.ipv4}:10000"];
labels.type = "app"; labels.type = "app";
labels.app = "v2ray"; labels.app = "sftpgo";
labels.host = "aquamarine";
} }
]; ];
} }
]
# --- Hosts --- #
++ (
lib.attrsets.foldlAttrs
(acc: hostname: addr:
acc
++ [
{
job_name = "node-exporter-${hostname}";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# All my NixOS hosts.
targets = ["${addr.ipv4}:9100"];
labels.type = "node";
labels.host = hostname;
}
]; ];
}
])
[]
myvars.networking.hostsAddr
);
# specifies Alertmanager instances the Prometheus server sends alerts to # specifies Alertmanager instances the Prometheus server sends alerts to
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config # https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config