Set up prometheus-phpfpm-exporter for various pools on bekkalokk #159

Merged
oysteikt merged 2 commits from prometheus-phpfpm-exporter into main 2026-07-27 13:58:47 +02:00
4 changed files with 71 additions and 0 deletions
+1
View File
@@ -13,6 +13,7 @@
./services/mediawiki
./services/nginx.nix
./services/phpfpm.nix
./services/prometheus-phpfpm-exporter.nix
./services/vaultwarden.nix
./services/webmail
./services/website
@@ -0,0 +1,54 @@
{ config, lib, values, ... }:
let
cfg = config.services.prometheus.exporters.php-fpm;
pools = [
"idp"
"mediawiki"
"pvv-nettsiden"
"roundcube"
"snappymail"
];
in
{
services.phpfpm.pools = lib.genAttrs pools (_: {
settings."pm.status_path" = "/status";
});
services.prometheus.exporters.php-fpm = {
enable = true;
listenAddress = "127.0.0.1";
extraFlags = [
"--phpfpm.scrape-uri=${lib.concatMapStringsSep "," (name: "unix://${config.services.phpfpm.pools.${name}.socket};/status") pools}"
];
};
systemd.services.prometheus-php-fpm-exporter.serviceConfig = {
Slice = "system-monitoring.slice";
SupplementaryGroups = [ config.services.nginx.group ];
RestrictAddressFamilies = lib.mkForce [
"AF_INET"
"AF_INET6"
"AF_UNIX"
];
};
services.nginx = lib.mkIf cfg.enable {
virtualHosts."www.pvv.ntnu.no" = lib.mkIf config.services.nginx.enable {
Review

non-blocking nit: This mkif is erratic behavior that could potentially make troubleshooting more difficult. I don't see any benefit from conditionally changing the configuration, as if nginx is disabled, this is not used for anything anyways.

non-blocking nit: This mkif is erratic behavior that could potentially make troubleshooting more difficult. I don't see any benefit from conditionally changing the configuration, as if nginx is disabled, this is not used for anything anyways.
Review

I'll open a new issue on making a treewide decision about these

I'll open a new issue on making a treewide decision about these
forceSSL = true;
enableACME = true;
kTLS = true;
locations."/prometheus-php-fpm-exporter/metrics" = {
proxyPass = "http://localhost:${toString cfg.port}/metrics";
extraConfig = ''
allow 127.0.0.1;
Review

non-blocking nit: we might want to go over the repo and replace most of these with 127.0.0.0/8, but this is probably absolutely fine

non-blocking nit: we might want to go over the repo and replace most of these with 127.0.0.0/8, but this is probably absolutely fine
Review

Let's solve these in anothet treewide

Let's solve these in anothet treewide
allow ::1;
allow ${values.hosts.ildkule.ipv4};
allow ${values.hosts.ildkule.ipv6};
deny all;
'';
};
};
};
}
@@ -7,6 +7,7 @@ in {
./machines.nix
./matrix-synapse.nix
./mysqld.nix
./phpfpm.nix
./postgres.nix
];
@@ -0,0 +1,15 @@
{ ... }:
{
services.prometheus.scrapeConfigs = [{
job_name = "phpfpm";
scheme = "https";
metrics_path = "/prometheus-php-fpm-exporter/metrics";
static_configs = [
{
labels.hostname = "bekkalokk";
targets = [ "www.pvv.ntnu.no:443" ];
}
];
}];
}