Skip to content
Snippets Groups Projects
make-monitoring.nix 2.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • { publicIPv4
    , hardware
    , publicStoragePort
    , ristrettoSigningKeyPath
    , passValue
    , sshUsers
    , stateVersion
    
    , monitoringvpnIPv4 ? null
    , monitoringvpnKeyDir ? null
    , vpnClientIPs ? null
    
    , nodeExporterTargets ? []
    , nginxExporterTargets ? []
    
    Florian Sesser's avatar
    Florian Sesser committed
    , hostsMap ? {}
    
      enableVpn = monitoringvpnKeyDir != null &&
                  monitoringvpnIPv4 != null &&
                  vpnClientIPs != null;
    
      vpnSecrets = if !enableVpn then {} else {
        "monitoringvpn-private-key" = {
          source = monitoringvpnKeyDir + "/server.key";
          destination = "/run/keys/monitoringvpn/server.key";
          owner.user = "root";
          owner.group = "root";
          permissions = "0400";
          action = ["sudo" "systemctl" "restart" "wireguard-monitoringvpn.service"];
        };
        "monitoringvpn-preshared-key" = {
          source = monitoringvpnKeyDir + "/preshared.key";
          destination = "/run/keys/monitoringvpn/preshared.key";
          owner.user = "root";
          owner.group = "root";
          permissions = "0400";
          action = ["sudo" "systemctl" "restart" "wireguard-monitoringvpn.service"];
        };
      };
    
    Florian Sesser's avatar
    Florian Sesser committed
    
      deployment = {
        targetHost = publicIPv4;
    
        secrets = vpnSecrets;
    
    Florian Sesser's avatar
    Florian Sesser committed
      };
    
      imports = [
        hardware
        ../../nixos/modules/monitoring/vpn/server.nix
    
    Florian Sesser's avatar
    Florian Sesser committed
        ../../nixos/modules/monitoring/server/grafana.nix
    
    Florian Sesser's avatar
    Florian Sesser committed
        ../../nixos/modules/monitoring/server/prometheus.nix
    
        ../../nixos/modules/monitoring/exporters/node.nix
    
        # Loki 0.3.0 from Nixpkgs 19.09 is too old and does not work:
        # ../../nixos/modules/monitoring/server/loki.nix
    
      services.private-storage.monitoring.vpn.server = if !enableVpn then {} else {
    
    Florian Sesser's avatar
    Florian Sesser committed
        enable = true;
    
    Florian Sesser's avatar
    Florian Sesser committed
        ip = monitoringvpnIPv4;
    
        pubKeysPath = monitoringvpnKeyDir;
    
    Florian Sesser's avatar
    Florian Sesser committed
      services.private-storage.monitoring.grafana = {
    
        domain = "monitoring.private.storage";
    
    Florian Sesser's avatar
    Florian Sesser committed
        prometheusUrl = "http://localhost:9090/";
        lokiUrl = "http://localhost:3100/";
      };
    
    
    Florian Sesser's avatar
    Florian Sesser committed
      services.private-storage.monitoring.prometheus = {
    
        inherit nodeExporterTargets;
        inherit nginxExporterTargets;
    
    Florian Sesser's avatar
    Florian Sesser committed
      system.stateVersion = stateVersion;
    
    Florian Sesser's avatar
    Florian Sesser committed
    
      networking.hosts = hostsMap;
    
    Florian Sesser's avatar
    Florian Sesser committed
    }