2024-06-07 19:41:03 +00:00
|
|
|
{ lib, config, machines, ... }:
|
2024-03-03 11:54:35 +00:00
|
|
|
let
|
2024-03-05 19:56:00 +00:00
|
|
|
cfg = config.lab.monitoring;
|
2024-03-03 11:54:35 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-03-05 19:56:00 +00:00
|
|
|
lab.monitoring = {
|
2024-03-03 11:54:35 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
default = true;
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
server.enable = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
networking.firewall.allowedTCPPorts = [ config.services.prometheus.exporters.node.port ]
|
2024-03-09 09:19:06 +00:00
|
|
|
++ lib.lists.optionals cfg.server.enable [ 80 ];
|
2024-03-03 11:54:35 +00:00
|
|
|
|
|
|
|
services.prometheus = {
|
|
|
|
enable = cfg.server.enable;
|
|
|
|
|
|
|
|
exporters = {
|
|
|
|
node = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
scrapeConfigs = lib.mkIf cfg.server.enable (
|
2024-08-30 15:49:11 +00:00
|
|
|
let
|
|
|
|
generated = lib.attrsets.mapAttrsToList
|
|
|
|
(name: machine: {
|
|
|
|
job_name = name;
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "${name}.dmz:${toString config.services.prometheus.exporters.node.port}" ];
|
|
|
|
}];
|
|
|
|
})
|
|
|
|
machines;
|
|
|
|
|
|
|
|
pikvm = {
|
|
|
|
job_name = "pikvm";
|
|
|
|
metrics_path = "/api/export/prometheus/metrics";
|
|
|
|
scheme = "https";
|
|
|
|
tls_config.insecure_skip_verify = true;
|
|
|
|
|
|
|
|
# We don't care about security here, it's behind a VPN.
|
|
|
|
basic_auth = {
|
|
|
|
username = "admin";
|
|
|
|
password = "admin";
|
|
|
|
};
|
|
|
|
|
2024-04-13 13:43:01 +00:00
|
|
|
static_configs = [{
|
2024-08-30 15:49:11 +00:00
|
|
|
targets = [ "pikvm.dmz" ];
|
2024-04-13 13:43:01 +00:00
|
|
|
}];
|
2024-08-30 15:49:11 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
generated ++ [ pikvm ]
|
2024-03-03 11:54:35 +00:00
|
|
|
);
|
|
|
|
};
|
2024-03-05 19:56:00 +00:00
|
|
|
|
2024-03-09 09:19:06 +00:00
|
|
|
services.nginx = lib.mkIf cfg.server.enable {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
virtualHosts."${config.networking.fqdn}" = {
|
2024-08-30 15:49:11 +00:00
|
|
|
locations."/" = {
|
2024-06-07 19:41:03 +00:00
|
|
|
proxyPass = "http://127.0.0.1:${toString config.services.prometheus.port}";
|
|
|
|
recommendedProxySettings = true;
|
2024-03-09 09:19:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-03-03 11:54:35 +00:00
|
|
|
};
|
|
|
|
}
|