diff --git a/flake.lock b/flake.lock index 64520c9..925bbbd 100644 --- a/flake.lock +++ b/flake.lock @@ -42,6 +42,26 @@ "url": "https://git.t-juice.club/torjus/labmon" } }, + "nixos-exporter": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1770417341, + "narHash": "sha256-Js2EJZlpol6eSWVGyYy6SAhIISKHfURnD6S+NBaLfHU=", + "ref": "refs/heads/master", + "rev": "e381038537bbee314fb0326ac7d17ec4f651fe1e", + "revCount": 7, + "type": "git", + "url": "https://git.t-juice.club/torjus/nixos-exporter" + }, + "original": { + "type": "git", + "url": "https://git.t-juice.club/torjus/nixos-exporter" + } + }, "nixpkgs": { "locked": { "lastModified": 1770136044, @@ -78,6 +98,7 @@ "inputs": { "alerttonotify": "alerttonotify", "labmon": "labmon", + "nixos-exporter": "nixos-exporter", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix" diff --git a/flake.nix b/flake.nix index e610ced..91712a2 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,10 @@ url = "git+https://git.t-juice.club/torjus/labmon?ref=master"; inputs.nixpkgs.follows = "nixpkgs-unstable"; }; + nixos-exporter = { + url = "git+https://git.t-juice.club/torjus/nixos-exporter"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; + }; }; outputs = @@ -27,6 +31,7 @@ sops-nix, alerttonotify, labmon, + nixos-exporter, ... }@inputs: let @@ -42,6 +47,17 @@ alerttonotify.overlays.default labmon.overlays.default ]; + # Common modules applied to all hosts + commonModules = [ + ( + { config, pkgs, ... }: + { + nixpkgs.overlays = commonOverlays; + } + ) + sops-nix.nixosModules.sops + nixos-exporter.nixosModules.default + ]; allSystems = [ "x86_64-linux" "aarch64-linux" @@ -58,15 +74,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/ns1 - sops-nix.nixosModules.sops ]; }; ns2 = nixpkgs.lib.nixosSystem { @@ -74,15 +83,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/ns2 - sops-nix.nixosModules.sops ]; }; ha1 = nixpkgs.lib.nixosSystem { @@ -90,15 +92,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/ha1 - sops-nix.nixosModules.sops ]; }; template1 = nixpkgs.lib.nixosSystem { @@ -106,15 +101,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/template - sops-nix.nixosModules.sops ]; }; template2 = nixpkgs.lib.nixosSystem { @@ -122,15 +110,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/template2 - sops-nix.nixosModules.sops ]; }; http-proxy = nixpkgs.lib.nixosSystem { @@ -138,15 +119,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/http-proxy - sops-nix.nixosModules.sops ]; }; ca = nixpkgs.lib.nixosSystem { @@ -154,15 +128,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/ca - sops-nix.nixosModules.sops ]; }; monitoring01 = nixpkgs.lib.nixosSystem { @@ -170,15 +137,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/monitoring01 - sops-nix.nixosModules.sops labmon.nixosModules.labmon ]; }; @@ -187,15 +147,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/jelly01 - sops-nix.nixosModules.sops ]; }; nix-cache01 = nixpkgs.lib.nixosSystem { @@ -203,15 +156,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/nix-cache01 - sops-nix.nixosModules.sops ]; }; pgdb1 = nixpkgs.lib.nixosSystem { @@ -219,15 +165,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/pgdb1 - sops-nix.nixosModules.sops ]; }; nats1 = nixpkgs.lib.nixosSystem { @@ -235,15 +174,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/nats1 - sops-nix.nixosModules.sops ]; }; testvm01 = nixpkgs.lib.nixosSystem { @@ -251,15 +183,8 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/testvm01 - sops-nix.nixosModules.sops ]; }; vault01 = nixpkgs.lib.nixosSystem { @@ -267,33 +192,19 @@ specialArgs = { inherit inputs self sops-nix; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) + modules = commonModules ++ [ ./hosts/vault01 - sops-nix.nixosModules.sops ]; }; - vaulttest01 = nixpkgs.lib.nixosSystem { - inherit system; - specialArgs = { - inherit inputs self sops-nix; + vaulttest01 = nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { + inherit inputs self sops-nix; + }; + modules = commonModules ++ [ + ./hosts/vaulttest01 + ]; }; - modules = [ - ( - { config, pkgs, ... }: - { - nixpkgs.overlays = commonOverlays; - } - ) - ./hosts/vaulttest01 - sops-nix.nixosModules.sops - ]; - }; }; packages = forAllSystems ( { pkgs }: diff --git a/system/monitoring/metrics.nix b/system/monitoring/metrics.nix index 45ac4d0..3a1ec44 100644 --- a/system/monitoring/metrics.nix +++ b/system/monitoring/metrics.nix @@ -18,4 +18,21 @@ "--systemd.collector.enable-ip-accounting" ]; }; + + services.prometheus.exporters.nixos = { + enable = true; + # Default port: 9971 + flake = { + enable = true; + url = "git+https://git.t-juice.club/torjus/nixos-servers.git"; + }; + }; + + # Register nixos-exporter as a Prometheus scrape target + homelab.monitoring.scrapeTargets = [ + { + job_name = "nixos-exporter"; + port = 9971; + } + ]; }