2024-03-05 19:56:00 +00:00
|
|
|
{ lib, pkgs, nixpkgs-unstable, 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
|
|
|
|
{
|
2024-03-05 19:56:00 +00:00
|
|
|
imports = [
|
|
|
|
"${nixpkgs-unstable}/nixos/modules/services/monitoring/gatus.nix"
|
2024-03-05 21:51:26 +00:00
|
|
|
./gatus-endpoints.nix
|
2024-03-05 19:56:00 +00:00
|
|
|
];
|
|
|
|
|
2024-03-03 11:54:35 +00:00
|
|
|
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 ]
|
|
|
|
++ lib.lists.optionals cfg.server.enable [ config.services.prometheus.port ];
|
|
|
|
|
|
|
|
services.prometheus = {
|
|
|
|
enable = cfg.server.enable;
|
|
|
|
|
|
|
|
exporters = {
|
|
|
|
node = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
scrapeConfigs = lib.mkIf cfg.server.enable (
|
|
|
|
lib.attrsets.mapAttrsToList
|
|
|
|
(name: machine:
|
|
|
|
let
|
|
|
|
domain = if machine.isPhysical then "hyp" else "dmz";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
job_name = name;
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "${name}.${domain}:${toString config.services.prometheus.exporters.node.port}" ];
|
|
|
|
}];
|
|
|
|
})
|
|
|
|
machines
|
|
|
|
);
|
|
|
|
};
|
2024-03-05 19:56:00 +00:00
|
|
|
|
|
|
|
services.gatus = lib.mkIf cfg.server.enable {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.unstable.gatus;
|
|
|
|
openFirewall = true;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
web.port = 4242;
|
2024-03-05 20:50:43 +00:00
|
|
|
|
2024-03-06 21:37:41 +00:00
|
|
|
storage = {
|
|
|
|
type = "sqlite";
|
|
|
|
path = "/srv/gatus/gatus.db";
|
|
|
|
};
|
|
|
|
|
2024-03-05 20:50:43 +00:00
|
|
|
alerting.email = {
|
|
|
|
from = "gatus@kun.is";
|
|
|
|
host = "mail.smtp2go.com";
|
|
|
|
port = 2525;
|
|
|
|
to = "pim@kunis.nl";
|
|
|
|
client.insecure = true;
|
2024-03-05 21:51:26 +00:00
|
|
|
|
2024-03-05 20:50:43 +00:00
|
|
|
default-alert = {
|
|
|
|
enabled = true;
|
|
|
|
failure-threshold = 2;
|
|
|
|
success-threshold = 1;
|
|
|
|
send-on-resolved = true;
|
|
|
|
};
|
|
|
|
};
|
2024-03-05 19:56:00 +00:00
|
|
|
};
|
|
|
|
};
|
2024-03-06 21:37:41 +00:00
|
|
|
|
|
|
|
system.activationScripts = lib.mkIf cfg.server.enable {
|
|
|
|
gatus = ''
|
|
|
|
mkdir -p /srv/gatus
|
|
|
|
chown gatus:gatus /srv/gatus
|
|
|
|
'';
|
|
|
|
};
|
2024-03-03 11:54:35 +00:00
|
|
|
};
|
|
|
|
}
|