2024-08-04 17:55:02 -04:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.aux.system.services.netdata;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
aux.system.services.netdata = {
|
|
|
|
enable = lib.mkEnableOption "Enables Netdata monitoring.";
|
|
|
|
auth = {
|
|
|
|
user = lib.mkOption {
|
|
|
|
default = "netdata";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Username for basic auth.";
|
|
|
|
};
|
|
|
|
password = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Password for basic auth.";
|
|
|
|
};
|
2024-08-23 14:16:18 -04:00
|
|
|
apiKey = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "API key for streaming data from a child to a parent.";
|
|
|
|
};
|
2024-08-04 17:55:02 -04:00
|
|
|
};
|
2024-08-23 14:16:18 -04:00
|
|
|
type = lib.mkOption {
|
|
|
|
default = "parent";
|
|
|
|
type = lib.types.enum [
|
|
|
|
"parent"
|
|
|
|
"child"
|
|
|
|
];
|
|
|
|
description = "Whether this is a parent (default: includes web UI) or child (no web UI - streaming only).";
|
|
|
|
example = "child";
|
|
|
|
};
|
2024-08-04 17:55:02 -04:00
|
|
|
url = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The complete URL where Netdata is hosted.";
|
|
|
|
example = "https://netdata.example.com";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-23 14:16:18 -04:00
|
|
|
config = lib.mkMerge [
|
2024-08-24 11:09:09 -04:00
|
|
|
(lib.mkIf (cfg.enable && cfg.type == "parent") {
|
2024-08-23 14:16:18 -04:00
|
|
|
services = {
|
|
|
|
nginx.virtualHosts."${cfg.url}" = {
|
2024-09-08 22:34:29 -04:00
|
|
|
useACMEHost =
|
|
|
|
let
|
|
|
|
parsedURL = (lib.strings.splitString "." cfg.url);
|
|
|
|
in
|
|
|
|
builtins.concatStringsSep "." [
|
|
|
|
(builtins.elemAt parsedURL 1)
|
|
|
|
(builtins.elemAt parsedURL 2)
|
|
|
|
];
|
2024-08-23 14:16:18 -04:00
|
|
|
forceSSL = true;
|
|
|
|
basicAuth = {
|
|
|
|
"${cfg.auth.user}" = cfg.auth.password;
|
|
|
|
};
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:19999";
|
|
|
|
extraConfig = ''
|
|
|
|
# Taken from https://learn.netdata.cloud/docs/netdata-agent/configuration/running-the-netdata-agent-behind-a-reverse-proxy/nginx
|
|
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
|
|
proxy_set_header X-Forwarded-Server $host;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
proxy_pass_request_headers on;
|
|
|
|
proxy_set_header Connection "keep-alive";
|
|
|
|
proxy_store off;
|
|
|
|
'';
|
|
|
|
};
|
2024-08-04 17:55:02 -04:00
|
|
|
};
|
2024-08-23 14:16:18 -04:00
|
|
|
|
|
|
|
netdata = {
|
2024-08-24 11:09:09 -04:00
|
|
|
enable = true;
|
|
|
|
package = pkgs.unstable.netdataCloud;
|
|
|
|
enableAnalyticsReporting = false;
|
2024-08-23 14:16:18 -04:00
|
|
|
configDir = {
|
|
|
|
# Enable nvidia-smi: https://nixos.wiki/wiki/Netdata#nvidia-smi
|
|
|
|
"python.d.conf" = pkgs.writeText "python.d.conf" ''
|
|
|
|
nvidia_smi: yes
|
|
|
|
'';
|
|
|
|
# Allow incoming streams
|
|
|
|
"stream.conf" = pkgs.writeText "stream.conf" ''
|
|
|
|
[${config.secrets.services.netdata.apiKey}]
|
|
|
|
enabled = yes
|
|
|
|
default history = 3600
|
|
|
|
default memory mode = dbengine
|
|
|
|
health enabled by default = auto
|
|
|
|
allow streaming from = *
|
|
|
|
'';
|
|
|
|
};
|
2024-08-04 17:55:02 -04:00
|
|
|
};
|
|
|
|
};
|
2024-08-23 14:16:18 -04:00
|
|
|
systemd.services.nginx.wants = [ config.systemd.services.netdata.name ];
|
|
|
|
})
|
2024-08-04 17:55:02 -04:00
|
|
|
|
2024-08-24 11:09:09 -04:00
|
|
|
(lib.mkIf (cfg.enable && cfg.type == "child") {
|
2024-08-23 14:16:18 -04:00
|
|
|
services.netdata = {
|
2024-08-24 11:09:09 -04:00
|
|
|
enable = true;
|
|
|
|
package = pkgs.unstable.netdataCloud;
|
|
|
|
enableAnalyticsReporting = false;
|
2024-08-23 14:16:18 -04:00
|
|
|
# Disable web UI
|
|
|
|
config = {
|
|
|
|
global = {
|
|
|
|
"memory mode" = "none";
|
|
|
|
};
|
|
|
|
web = {
|
|
|
|
mode = "none";
|
|
|
|
"accept a streaming request every seconds" = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# Set up streaming
|
2024-08-04 17:55:02 -04:00
|
|
|
configDir = {
|
2024-08-23 14:16:18 -04:00
|
|
|
"stream.conf" = pkgs.writeText "stream.conf" ''
|
|
|
|
[stream]
|
|
|
|
enabled = yes
|
2024-08-23 14:49:27 -04:00
|
|
|
destination = ${cfg.url}:443:SSL
|
2024-08-23 14:16:18 -04:00
|
|
|
api key = ${cfg.auth.apiKey}
|
|
|
|
[${cfg.auth.apiKey}]
|
|
|
|
enabled = yes
|
2024-08-04 17:55:02 -04:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-08-23 14:16:18 -04:00
|
|
|
})
|
|
|
|
];
|
2024-08-04 17:55:02 -04:00
|
|
|
}
|