From dcebc6afbdde136d66864069152e05344f177559 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Sun, 22 Sep 2024 15:42:59 +0300 Subject: [PATCH] feat: cadvisor --- roles/cadvisor.nix | 32 +++++++++++++++++++++++++++++++ roles/default.nix | 1 + systems/hosts/metrics/default.nix | 9 +++++++++ systems/profiles/lxc/roles.nix | 5 +++++ 4 files changed, 47 insertions(+) create mode 100644 roles/cadvisor.nix diff --git a/roles/cadvisor.nix b/roles/cadvisor.nix new file mode 100644 index 0000000..2fd0597 --- /dev/null +++ b/roles/cadvisor.nix @@ -0,0 +1,32 @@ +{ + lib, + config, + ... +}: let + cfg = config.roles.cadvisor; +in { + options.roles.cadvisor = { + enable = lib.mkEnableOption "cadvisor"; + port = lib.mkOption { + type = lib.types.port; + default = 9080; + }; + openFirewall = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Wheter to open firewall port for cadvisor"; + }; + }; + + config = lib.mkIf cfg.enable { + networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ + cfg.port + ]; + + services.cadvisor = { + enable = true; + listenAddress = "0.0.0.0"; + port = cfg.port; + }; + }; +} diff --git a/roles/default.nix b/roles/default.nix index 9a11e44..c05a391 100644 --- a/roles/default.nix +++ b/roles/default.nix @@ -7,6 +7,7 @@ ./audio.nix ./base.nix ./bluetooth.nix + ./cadvisor.nix ./docker.nix ./git.nix ./hyprland.nix diff --git a/systems/hosts/metrics/default.nix b/systems/hosts/metrics/default.nix index 90adbd2..aadcc0e 100644 --- a/systems/hosts/metrics/default.nix +++ b/systems/hosts/metrics/default.nix @@ -34,6 +34,15 @@ in { ]; } + { + job_name = "cadvisor"; + static_configs = [ + { + targets = map (x: x + ":9080") (builtins.attrNames (artautil.getDNSEntries "lxc")); + } + ]; + } + { job_name = "node"; static_configs = [ diff --git a/systems/profiles/lxc/roles.nix b/systems/profiles/lxc/roles.nix index 6ca8927..23a255a 100644 --- a/systems/profiles/lxc/roles.nix +++ b/systems/profiles/lxc/roles.nix @@ -13,4 +13,9 @@ }; systemd.enable = true; }; + + roles.cadvisor = { + enable = true; + openFirewall = true; + }; } -- 2.44.1