85 lines
1.8 KiB
Nix
85 lines
1.8 KiB
Nix
|
# SPDX-FileCopyrightText: 2024 Maurice Debray <maurice.debray@dgnum.eu>
|
||
|
# SPDX-FileCopyrightText: 2024 Ryan Lahfa <ryan.lahfa@dgnum.eu>
|
||
|
#
|
||
|
# SPDX-License-Identifier: EUPL-1.2
|
||
|
|
||
|
{
|
||
|
pkgs,
|
||
|
sources,
|
||
|
config,
|
||
|
lib,
|
||
|
...
|
||
|
}:
|
||
|
let
|
||
|
inherit (lib)
|
||
|
optional
|
||
|
mapAttrs
|
||
|
mapAttrs'
|
||
|
mkDefault
|
||
|
mkIf
|
||
|
mkOption
|
||
|
nameValuePair
|
||
|
recursiveUpdate
|
||
|
;
|
||
|
|
||
|
inherit (lib.types) attrsOf bool port;
|
||
|
|
||
|
cfg = config.dgn-monitoring.exporters;
|
||
|
in
|
||
|
|
||
|
{
|
||
|
options.dgn-monitoring.exporters = {
|
||
|
enable = mkOption {
|
||
|
type = bool;
|
||
|
default = config.dgn-monitoring.enable;
|
||
|
description = ''
|
||
|
Whether to enable standard exporters for the dgnum monitoring system.
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
ports = mkOption {
|
||
|
type = attrsOf port;
|
||
|
description = ''
|
||
|
Ports to listen on for each exporter.
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
imports = [ "${sources.cgroup-exporter}/nix/module.nix" ];
|
||
|
|
||
|
config = mkIf cfg.enable {
|
||
|
dgn-monitoring.exporters.ports = mapAttrs (_: mkDefault) {
|
||
|
node = 9002;
|
||
|
cgroup = 9003;
|
||
|
};
|
||
|
|
||
|
services.prometheus = {
|
||
|
exporters =
|
||
|
recursiveUpdate
|
||
|
{
|
||
|
node = {
|
||
|
enable = true;
|
||
|
enabledCollectors = [
|
||
|
"processes"
|
||
|
"systemd"
|
||
|
] ++ (optional config.boot.zfs.enabled "zfs");
|
||
|
};
|
||
|
|
||
|
cgroup = {
|
||
|
enable = true;
|
||
|
package = pkgs.callPackage "${sources.cgroup-exporter}/nix/package.nix" { };
|
||
|
};
|
||
|
}
|
||
|
(
|
||
|
mapAttrs (_: port: {
|
||
|
inherit port;
|
||
|
# NOTE: We always listen on localhost, as the agent runs on the same machine
|
||
|
listenAddress = "127.0.0.1";
|
||
|
}) cfg.ports
|
||
|
);
|
||
|
};
|
||
|
|
||
|
dgn-web.internalPorts = mapAttrs' (name: nameValuePair "${name}-exporter") cfg.ports;
|
||
|
};
|
||
|
}
|