add nginx reverse proxy behind gatus and prometheus

This commit is contained in:
Pim Kunis 2024-03-09 10:19:06 +01:00
parent 2f608a764a
commit 01138760f4

View file

@ -1,6 +1,7 @@
{ lib, pkgs, nixpkgs-unstable, config, machines, ... }: { lib, pkgs, nixpkgs-unstable, config, machines, ... }:
let let
cfg = config.lab.monitoring; cfg = config.lab.monitoring;
gatusPort = 8080;
in in
{ {
imports = [ imports = [
@ -24,10 +25,11 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ config.services.prometheus.exporters.node.port ] networking.firewall.allowedTCPPorts = [ config.services.prometheus.exporters.node.port ]
++ lib.lists.optionals cfg.server.enable [ config.services.prometheus.port ]; ++ lib.lists.optionals cfg.server.enable [ 80 ];
services.prometheus = { services.prometheus = {
enable = cfg.server.enable; enable = cfg.server.enable;
webExternalUrl = "/prometheus";
exporters = { exporters = {
node = { node = {
@ -39,6 +41,7 @@ in
lib.attrsets.mapAttrsToList lib.attrsets.mapAttrsToList
(name: machine: (name: machine:
let let
# TODO: should finally create my own lib...
domain = if machine.isPhysical then "hyp" else "dmz"; domain = if machine.isPhysical then "hyp" else "dmz";
in in
{ {
@ -54,10 +57,9 @@ in
services.gatus = lib.mkIf cfg.server.enable { services.gatus = lib.mkIf cfg.server.enable {
enable = true; enable = true;
package = pkgs.unstable.gatus; package = pkgs.unstable.gatus;
openFirewall = true;
settings = { settings = {
web.port = 4242; web.port = gatusPort;
storage = { storage = {
type = "sqlite"; type = "sqlite";
@ -87,5 +89,23 @@ in
chown gatus:gatus /srv/gatus chown gatus:gatus /srv/gatus
''; '';
}; };
services.nginx = lib.mkIf cfg.server.enable {
enable = true;
virtualHosts."${config.networking.fqdn}" = {
locations = {
"/" = {
proxyPass = "http://127.0.0.1:${toString gatusPort}";
recommendedProxySettings = true;
};
"/prometheus/" = {
proxyPass = "http://127.0.0.1:${toString config.services.prometheus.port}";
recommendedProxySettings = true;
};
};
};
};
}; };
} }