Files
nix-config-ryan4yin/hosts/k8s/kubevirt-youko/aquamarine/monitoring/victoriametrics.nix
T
Ryan Yin c292509351 refactor: retire the aquamarine VM host
Aquamarine's services now run directly on kubevirt-youko, so the guest
definition is no longer needed:

- move its service modules to hosts/k8s/kubevirt-youko/aquamarine/ and
  drop the explicit import list, leaving aquamarine-services.nix with
  just its IP and secret groups
- delete the guest base, journald override, output entry and home config
- repoint the eval tests that read the guest's config to kubevirt-youko
- drop the now-dead 'aqua' colmena recipe and its image upload

The aqua KubeVirt VM itself is deleted separately; the name is kept in
the docs for a possible later test microvm/qemu-vm on idols-ai.
2026-09-21 15:45:02 +08:00

206 lines
6.5 KiB
Nix

{
lib,
myvars,
...
}:
let
# Powered-off hosts (SBCs) plus shoukei (exporter disabled on the
# machine); remove entries when they come back online.
offlineHosts = [
"shoukei"
"suzu"
"suzi"
"yukina"
"nozomi"
"chiaya"
"rakushun"
"mitsuha"
];
in
{
# Since victoriametrics use DynamicUser, the user & group do not exists before the service starts.
# this group is used as a supplementary Unix group for the service to access our data dir(/data/apps/xxx)
users.groups.victoriametrics-data = { };
# Workaround for victoriametrics to store data in another place
# https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html#Type
systemd.tmpfiles.rules = [
"d /data/apps/victoriametrics 0770 root victoriametrics-data - -"
];
# Symlinks do not work with DynamicUser, so we should use bind mount here.
# https://github.com/systemd/systemd/issues/25097#issuecomment-1929074961
systemd.services.victoriametrics.serviceConfig = {
SupplementaryGroups = [ "victoriametrics-data" ];
BindPaths = [ "/data/apps/victoriametrics:/var/lib/victoriametrics:rbind" ];
};
# https://victoriametrics.io/docs/victoriametrics/latest/configuration/configuration/
services.victoriametrics = {
enable = true;
listenAddress = "127.0.0.1:9090";
retentionPeriod = "30d";
extraOptions = [
# Allowed percent of system memory VictoriaMetrics caches may occupy.
"-memory.allowedPercent=50"
# Deduplicate samples with the same timestamp within one scrape interval
# (e.g. from vmagent retries/HA replicas). Without this the storage rejects
# them with "duplicate sample for timestamp; overrides not allowed".
# Keep it >= the senders' scrapeInterval (vmagent 20s, in-cluster 30s).
"-dedup.minScrapeInterval=30s"
];
# Directory below /var/lib to store victoriametrics metrics data.
stateDir = "victoriametrics";
# specifies a set of targets and parameters describing how to scrape metrics from them.
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
prometheusConfig = {
scrape_configs = [
# --- Homelab Applications --- #
# suzi is powered off, disable scraping until it comes back online.
/*
{
job_name = "dnsmasq-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
targets = [ "${myvars.networking.hostsAddr.suzi.ipv4}:9153" ];
labels.type = "app";
labels.app = "dnsmasq";
labels.host = "suzi";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
*/
{
job_name = "v2ray-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# same-host exporter bound to loopback (127.0.0.1:9153)
targets = [ "127.0.0.1:9153" ];
labels.type = "app";
labels.app = "v2ray";
labels.host = "aquamarine";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
{
job_name = "nut-exporter-homelab-ups";
scrape_interval = "30s";
metrics_path = "/ups_metrics";
params.ups = [ "homelab" ];
static_configs = [
{
targets = [ "${myvars.networking.hostsAddr.kubevirt-shushou.ipv4}:9199" ];
labels.type = "app";
labels.app = "nut";
labels.host = "kubevirt-shushou";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
{
job_name = "postgres-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# same-host exporter bound to loopback (127.0.0.1:9187)
targets = [ "127.0.0.1:9187" ];
labels.type = "app";
labels.app = "postgresql";
labels.host = "aquamarine";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
{
job_name = "sftpgo-embedded-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# same-host exporter bound to loopback (127.0.0.1:10000)
targets = [ "127.0.0.1:10000" ];
labels.type = "app";
labels.app = "sftpgo";
labels.host = "aquamarine";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
{
job_name = "alertmanager-embedded-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
targets = [ "localhost:9093" ];
labels.type = "app";
labels.app = "alertmanager";
labels.host = "aquamarine";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
{
job_name = "victoriametrics-embedded-exporter";
scrape_interval = "30s";
metrics_path = "/metrics";
static_configs = [
{
# scrape vm itself
targets = [ "localhost:9090" ];
labels.type = "app";
labels.app = "victoriametrics";
labels.host = "aquamarine";
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
]
# --- 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;
labels.env = "homelab";
labels.cluster = "homelab";
}
];
}
]
)
[ ]
(lib.attrsets.filterAttrs (n: _: !(builtins.elem n offlineHosts)) myvars.networking.hostsAddr)
);
};
};
}