monitoring: add nixos-exporter to all hosts
All checks were successful
Run nix flake check / flake-check (push) Successful in 3m16s
Run nix flake check / flake-check (pull_request) Successful in 3m14s

Add nixos-exporter prometheus exporter to track NixOS generation metrics
and flake revision status across all hosts.

Changes:
- Add nixos-exporter flake input
- Add commonModules list in flake.nix for modules shared by all hosts
- Enable nixos-exporter in system/monitoring/metrics.nix
- Configure Prometheus to scrape nixos-exporter on all hosts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 23:55:29 +01:00
parent f2c30cc24f
commit 97ff774d3f
3 changed files with 76 additions and 127 deletions

21
flake.lock generated
View File

@@ -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"

151
flake.nix
View File

@@ -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,15 +192,8 @@
specialArgs = {
inherit inputs self sops-nix;
};
modules = [
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = commonOverlays;
}
)
modules = commonModules ++ [
./hosts/vault01
sops-nix.nixosModules.sops
];
};
vaulttest01 = nixpkgs.lib.nixosSystem {
@@ -283,15 +201,8 @@
specialArgs = {
inherit inputs self sops-nix;
};
modules = [
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = commonOverlays;
}
)
modules = commonModules ++ [
./hosts/vaulttest01
sops-nix.nixosModules.sops
];
};
};

View File

@@ -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;
}
];
}