Added node exporters on more machines

This commit is contained in:
Alejandro Angulo 2023-09-10 09:20:11 -07:00
parent 1f44933617
commit 8f813f3865
Signed by: alejandro-angulo
GPG key ID: 75579581C74554B6
5 changed files with 29 additions and 29 deletions

View file

@ -77,6 +77,9 @@
user = "root"; user = "root";
sshUser = "alejandro"; sshUser = "alejandro";
path = deployPkgs.deploy-rs.lib.aarch64-linux.activate.nixos inputs.self.nixosConfigurations.pi4; path = deployPkgs.deploy-rs.lib.aarch64-linux.activate.nixos inputs.self.nixosConfigurations.pi4;
# Usually deploy from an x86_64 machine and don't want to bother
# trying to build an aarch64 derivation
remoteBuild = true;
}; };
}; };
}; };

View file

@ -11,54 +11,49 @@ with lib; let
in { in {
options.aa.services.prometheus = with types; { options.aa.services.prometheus = with types; {
enable = mkEnableOption "prometheus"; enable = mkEnableOption "prometheus";
acmeCertName = mkOption { enableServer = mkOption {
type = str; type = bool;
default = ""; default = false;
description = '' description = "Whether or not to enable the prometheus server";
If set to a non-empty string, forces SSL with the supplied acme };
certificate. enableNodeExporter = mkOption {
''; type = bool;
default = true;
description = "Whether or not to enable the node exporter";
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.prometheus = { services.prometheus = {
enable = true; enable = cfg.enableServer;
exporters = { exporters = {
node = { node = {
enable = true; enable = cfg.enableNodeExporter;
enabledCollectors = ["systemd"]; enabledCollectors = ["systemd"];
port = 9002; port = 9002;
openFirewall = true;
}; };
}; };
scrapeConfigs = [ scrapeConfigs = mkIf cfg.enableServer [
{ {
job_name = "foo"; job_name = "node";
static_configs = [ static_configs = [
{ {
targets = ["127.0.0.1:${toString exporters.node.port}"]; # TODO: How to automatically generate this whenever an exporter
# is configured
targets = [
"node:${toString exporters.node.port}"
"gospel:${toString exporters.node.port}"
"pi4:${toString exporters.node.port}"
];
} }
]; ];
} }
]; ];
}; };
services.nginx = { networking.firewall = mkIf cfg.enableServer {
enable = true; allowedTCPPorts = [config.services.prometheus.port];
virtualHosts."prometheus.${cfg.acmeCertName}" =
{
locations."/" = {
proxyPass = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}";
};
}
// lib.optionalAttrs (cfg.acmeCertName != "") {
forceSSL = true;
useACMEHost = cfg.acmeCertName;
};
};
networking.firewall = {
allowedTCPPorts = [80 443];
}; };
}; };
} }

View file

@ -41,6 +41,7 @@
enable = true; enable = true;
acmeCertName = "kilonull.com"; acmeCertName = "kilonull.com";
}; };
services.prometheus.enable = true;
security.acme = { security.acme = {
enable = true; enable = true;

View file

@ -56,6 +56,7 @@
}; };
}; };
}; };
services.prometheus.enable = true;
hardware.audio.enable = true; hardware.audio.enable = true;
hardware.bluetooth.enable = true; hardware.bluetooth.enable = true;

View file

@ -36,7 +36,7 @@
}; };
services.prometheus = { services.prometheus = {
enable = true; enable = true;
acmeCertName = "kilonull.com"; enableServer = true;
}; };
services.loki = { services.loki = {
enable = true; enable = true;