{ ... }: {
  imports = [
    ../../templates/proxmox-lxc.nix
    ../../server.nix
    ../../features/dns-cache.nix
    ../../features/telemetry
  ];

  networking.hostName = "monitoring";
  system.stateVersion = "24.05";
  nixpkgs.hostPlatform = "x86_64-linux";

  services.grafana = {
    enable = true;
    settings = {
      server = {
        http_addr = "0.0.0.0";
        http_port = 3000;
        domain = "monitoring.hoki-porgy.ts.net";
      };
    };

    provision = {
      enable = true;
      datasources.settings.datasources = [
        {
          url = "http://localhost:4000";
          type = "prometheus";
          name = "Prometheus";
        }
      ];
    };
  };
  
  services.prometheus = {
    enable = true;
    port = 4000;
    
    scrapeConfigs = let
      static = name: ports: { 
        job_name = name;
        static_configs = [
          { 
            targets = map (port: "${name}.hoki-porgy.ts.net:${builtins.toString port}") ports;
          }
        ]; 
      };
      ports = {
        node = 14200;
        nginx = 14201;
        pve = 14210;
        plex = 14220;
        smb = 14221;
        transmission = 14222;
      };
    in with ports; [
      (static "aerial" [ node ])
      (static "cider" [ node ])
      (static "dis-sociat-ing" [ node ])
      (static "exit-node" [ node ])
      (static "git" [ node ])
      (static "hive" [ node pve ])
      (static "ingress-proxy" [ node nginx ])
      (static "monitoring" [ node ])
      (static "mumble" [ node ])
      (static "nas0" [ node ])
      (static "nextcloud" [ node ])
      (static "opnsense" [ node ])
      (static "pihole" [ node ])
      (static "plex" [ node plex ])
      (static "porcelain-doll-repair" [ node ])
      (static "ps2live" [ node ])
      (static "sapphic-engineer" [ node ])
      (static "seedbox" [ node transmission ])
      (static "static-sites" [ node nginx ])
      (static "ts3" [ node ])
      {
        job_name = "saerro";
        static_configs = [
          { targets = [ "saerro.ps2.live" ]; }
        ];
        metrics_path = "/metrics/combined";
        scheme = "https";
      }
      {
        job_name = "porcelain-doll-repair-iceshrimp";
        static_configs = [
          { targets = [ "porcelain.doll.repair" ]; }
        ];
        metrics_path = "/metrics";
        scheme = "https";
      }
      {
        job_name = "dis-sociat-ing-iceshrimp";
        static_configs = [
          { targets = [ "dis.sociat.ing" ]; }
        ];
        metrics_path = "/metrics";
        scheme = "https";
      }
      {
        job_name = "plapkit";
        static_configs = [
          { targets = [ "i-pk.noe.sh" ]; }
        ];
        metrics_path = "/metrics";
        scheme = "https";
      }
    ];
  };

}
