diff options
Diffstat (limited to 'nixpkgs/nixos/modules/services/monitoring/netdata.nix')
-rw-r--r-- | nixpkgs/nixos/modules/services/monitoring/netdata.nix | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/nixpkgs/nixos/modules/services/monitoring/netdata.nix b/nixpkgs/nixos/modules/services/monitoring/netdata.nix index bd0dea83e1a8..89a842023c88 100644 --- a/nixpkgs/nixos/modules/services/monitoring/netdata.nix +++ b/nixpkgs/nixos/modules/services/monitoring/netdata.nix @@ -159,6 +159,15 @@ in { ''; }; + claimTokenFile = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + If set, automatically registers the agent using the given claim token + file. + ''; + }; + enableAnalyticsReporting = mkOption { type = types.bool; default = false; @@ -216,7 +225,7 @@ in { ExecStart = "${cfg.package}/bin/netdata -P /run/netdata/netdata.pid -D -c /etc/netdata/netdata.conf"; ExecReload = "${pkgs.util-linux}/bin/kill -s HUP -s USR1 -s USR2 $MAINPID"; ExecStartPost = pkgs.writeShellScript "wait-for-netdata-up" '' - while [ "$(${pkgs.netdata}/bin/netdatacli ping)" != pong ]; do sleep 0.5; done + while [ "$(${cfg.package}/bin/netdatacli ping)" != pong ]; do sleep 0.5; done ''; TimeoutStopSec = cfg.deadlineBeforeStopSec; @@ -260,7 +269,25 @@ in { PrivateTmp = true; ProtectControlGroups = true; PrivateMounts = true; - }; + } // (lib.optionalAttrs (cfg.claimTokenFile != null) { + LoadCredential = [ + "netdata_claim_token:${cfg.claimTokenFile}" + ]; + + ExecStartPre = pkgs.writeShellScript "netdata-claim" '' + set -euo pipefail + + if [[ -f /var/lib/netdata/cloud.d/claimed_id ]]; then + # Already registered + exit + fi + + exec ${cfg.package}/bin/netdata-claim.sh \ + -token="$(< "$CREDENTIALS_DIRECTORY/netdata_claim_token")" \ + -url=https://app.netdata.cloud \ + -daemon-not-running + ''; + }); }; systemd.enableCgroupAccounting = true; |