chore(monitoring): nf-fmt-nix

This commit is contained in:
arcnmx 2024-05-30 14:10:18 -07:00
parent 6fb140c7e6
commit a0a7df1b0e
6 changed files with 164 additions and 141 deletions

View file

@ -11,18 +11,24 @@
nodeExporterSystems =
filter (
system:
system.config.access.online.enable &&
system.config.exports.prometheus.exporter.services != [ ]
system.config.access.online.enable
&& system.config.exports.prometheus.exporter.services != []
)
(attrValues systems);
mkPortTarget = { system, service, portName }: let
mkPortTarget = {
system,
service,
portName,
}: let
port = service.ports.${portName};
in "${access.getAddressFor system.config.name "lan"}:${toString port.port}";
mkServiceConfig = system: serviceName: let
service = system.config.exports.services.${serviceName};
targets = map (portName: mkPortTarget {
targets = map (portName:
mkPortTarget {
inherit system service portName;
}) service.prometheus.exporter.ports;
})
service.prometheus.exporter.ports;
in {
job_name = "${system.config.name}-${service.id}";
static_configs = [

View file

@ -7,8 +7,9 @@
inherit (lib.attrsets) attrValues;
inherit (lib.lists) concatMap toList;
allExporters = let
exporters = removeAttrs config.services.prometheus.exporters [ "unifi-poller" ];
in concatMap toList (attrValues exporters);
exporters = removeAttrs config.services.prometheus.exporters ["unifi-poller"];
in
concatMap toList (attrValues exporters);
in {
config = {
services.prometheus.exporters = {
@ -57,8 +58,11 @@ in {
}
];
};
networking.firewall.interfaces.lan.allowedTCPPorts = map (exporter:
mkIf (exporter.enable && !exporter.openFirewall) 999
) allExporters;
networking.firewall.interfaces.lan.allowedTCPPorts =
map (
exporter:
mkIf (exporter.enable && !exporter.openFirewall) exporter.port
)
allExporters;
};
}

View file

@ -1,8 +1,5 @@
let
portModule = {
lib,
...
}: let
portModule = {lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.prometheus = with lib.types; {
@ -27,7 +24,7 @@ let
};
labels = mkOption {
type = attrsOf str;
default = { };
default = {};
};
};
};
@ -41,17 +38,22 @@ let
exporter.ports = mkOptionDefault (attrNames exporterPorts);
};
};
in {
in
{
config,
gensokyo-zone,
lib,
...
}: let
}: let
inherit (gensokyo-zone.lib) mapListToAttrs mapAlmostOptionDefaults mkAlmostOptionDefault;
inherit (lib.options) mkOption;
inherit (lib.modules) mkIf mkOptionDefault;
inherit (lib.attrsets) attrNames filterAttrs nameValuePair;
mkExporter = { name, port }: nameValuePair "prometheus-exporters-${name}" ({config, ...}: {
mkExporter = {
name,
port,
}:
nameValuePair "prometheus-exporters-${name}" ({config, ...}: {
nixos = {
serviceAttrPath = ["services" "prometheus" "exporters" name];
assertions = mkIf config.enable [
@ -61,17 +63,22 @@ in {
})
];
};
ports.default = mapAlmostOptionDefaults {
ports.default =
mapAlmostOptionDefaults {
inherit port;
protocol = "http";
} // {
}
// {
prometheus.exporter.enable = true;
};
});
exporters = mapListToAttrs mkExporter [
{ name = "node"; port = 9091; }
{
name = "node";
port = 9091;
}
];
in {
in {
options.exports = with lib.types; {
prometheus = {
exporter.services = mkOption {
@ -85,11 +92,12 @@ in {
};
};
config.exports.prometheus = let
exporterServices = filterAttrs (_: service: service.enable && service.prometheus.exporter.ports != [ ]) config.exports.services;
exporterServices = filterAttrs (_: service: service.enable && service.prometheus.exporter.ports != []) config.exports.services;
in {
exporter.services = mkOptionDefault (attrNames exporterServices);
};
config.exports.services = {
config.exports.services =
{
prometheus = {config, ...}: {
id = mkAlmostOptionDefault "prometheus";
nixos = {
@ -149,12 +157,15 @@ in {
})
];
};
ports.default = mapAlmostOptionDefaults {
ports.default =
mapAlmostOptionDefaults {
port = 9094;
protocol = "http";
} // {
}
// {
prometheus.exporter.enable = true;
};
};
} // exporters;
}
}
// exporters;
}

View file

@ -146,7 +146,9 @@
};
in {
options.exports = with lib.types; {
defaultServices = mkEnableOption "common base services" // {
defaultServices =
mkEnableOption "common base services"
// {
default = config.type == "NixOS";
};
services = mkOption {
@ -170,7 +172,7 @@ in {
"sshd"
"prometheus-exporters-node"
"promtail"
] (_: { enable = mkAlmostOptionDefault true; });
] (_: {enable = mkAlmostOptionDefault true;});
in {
services = mkIf cfg.defaultServices defaultServices;
};