summary refs log tree commit diff
path: root/modules/foundation/monitoring/client.nix
blob: 6c91639ff5fc379938e168135137940811d6fe2e (generated by cgit-pink 1.4.1 (git 2.36.1) at 2026-04-26 05:36:41 +0000
f { color: #FF0 } /* Name.Function */ .highlight .nl { color: #DDD } /* Name.Label */ .highlight .nn { color: #DDD } /* Name.Namespace */ .highlight .nx { color: #DDD } /* Name.Other */ .highlight .py { color: #DDD } /* Name.Property */ .highlight .nt { color: #DDD } /* Name.Tag */ .highlight .nv { color: #EEDD82 } /* Name.Variable */ .highlight .ow { color: #F00 } /* Operator.Word */ .highlight .pm { color: #DDD } /* Punctuation.Marker */ .highlight .w { color: #DDD } /* Text.Whitespace */ .highlight .mb { color: #F0F } /* Literal.Number.Bin */ .highlight .mf { color: #F0F } /* Literal.Number.Float */ .highlight .mh { color: #F0F } /* Literal.Number.Hex */ .highlight .mi { color: #F0F } /* Literal.Number.Integer */ .highlight .mo { color: #F0F } /* Literal.Number.Oct */ .highlight .sa { color: #87CEEB } /* Literal.String.Affix */ .highlight .sb { color: #87CEEB } /* Literal.String.Backtick */ .highlight .sc { color: #87CEEB } /* Literal.String.Char */ .highlight .dl { color: #87CEEB } /* Literal.String.Delimiter */ .highlight .sd { color: #87CEEB } /* Literal.String.Doc */ .highlight .s2 { color: #87CEEB } /* Literal.String.Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
{
  lib,
  config,

  services,
  listenAddress,
  nodeExporterPort,
  nginxExporterPort,
  nginxLogExporterPort,
  cadvisorExporterPort,
  dnsmasqExporterPort,
  ...
}:

{
  foundation.tailnetServices =
    let
      exporter = name: "promethes-${name}-exporter";
    in
    [
      (exporter "node")
      (exporter "nginx")
      (exporter "nginxlog")
      # note: it doesn't matter if the service is only enabled conditionally.
      (exporter "dnsmasq")

      "cadvisor"
    ];

  services = {
    prometheus.exporters = {
      node = {
        enable = true;
        openFirewall = false;
        port = nodeExporterPort;
        inherit listenAddress;
      };

      nginx = {
        enable = true;
        openFirewall = false;
        port = nginxExporterPort;
        inherit listenAddress;
      };

      nginxlog = {
        enable = true;
        openFirewall = false;
        port = nginxLogExporterPort;
        inherit listenAddress;

        user = "nginx";
        group = "nginx";

        settings.namespaces =
          let
            namespace = name: log: {
              inherit name;
              source_files = [ log ];
              parser = "json";
              metrics_override.prefix = "nginx";
              namespace_label = "vhost";
            };

            vhost = name: (namespace name "/var/log/nginx/${name}.access.log");
          in
          [
            (namespace "default" "/var/log/nginx/access.log")
          ]
          ++ (map vhost services);
      };

      dnsmasq = lib.mkIf config.services.dnsmasq.enable {
        enable = true;
        port = dnsmasqExporterPort;
        inherit listenAddress;
      };
    };

    cadvisor = {
      enable = true;
      port = cadvisorExporterPort;
      inherit listenAddress;
    };
  };
}