This repository has been archived on 2025-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
nixos-servers/nixos-modules/monitoring/default.nix

58 lines
1.3 KiB
Nix
Raw Normal View History

{ lib, config, machines, ... }:
let
2024-03-05 20:56:00 +01:00
cfg = config.lab.monitoring;
in
{
options = {
2024-03-05 20:56:00 +01:00
lab.monitoring = {
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 ]
++ lib.lists.optionals cfg.server.enable [ 80 ];
services.prometheus = {
enable = cfg.server.enable;
webExternalUrl = "/prometheus";
exporters = {
node = {
enable = true;
};
};
scrapeConfigs = lib.mkIf cfg.server.enable (
lib.attrsets.mapAttrsToList
2024-04-13 15:43:01 +02:00
(name: machine: {
job_name = name;
static_configs = [{
targets = [ "${name}.dmz:${toString config.services.prometheus.exporters.node.port}" ];
}];
})
machines
);
};
2024-03-05 20:56:00 +01:00
services.nginx = lib.mkIf cfg.server.enable {
enable = true;
virtualHosts."${config.networking.fqdn}" = {
locations."/prometheus/" = {
proxyPass = "http://127.0.0.1:${toString config.services.prometheus.port}";
recommendedProxySettings = true;
};
};
};
};
}