summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/prometheus/exporters
diff options
context:
space:
mode:
authorGaël Reyrol <me@gaelreyrol.dev>2023-06-28 20:57:01 +0200
committerGaël Reyrol <me@gaelreyrol.dev>2023-06-28 22:11:36 +0200
commit1a821e7bf5254d84679273dd2f2e8f74f958d871 (patch)
tree76af4df9d4077628d3347962e027558a437f5e5f /nixos/modules/services/monitoring/prometheus/exporters
parent28fb612abc4fcc7e5c460c8e94dc03fb748b3e13 (diff)
downloadnixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar.gz
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar.bz2
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar.lz
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar.xz
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.tar.zst
nixpkgs-1a821e7bf5254d84679273dd2f2e8f74f958d871.zip
nixos/prometheus-exporters: add php-fpm
Diffstat (limited to 'nixos/modules/services/monitoring/prometheus/exporters')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/php-fpm.nix65
1 files changed, 65 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/php-fpm.nix b/nixos/modules/services/monitoring/prometheus/exporters/php-fpm.nix
new file mode 100644
index 00000000000..8f6942002f7
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/php-fpm.nix
@@ -0,0 +1,65 @@
+{ config
+, lib
+, pkgs
+, options
+}:
+
+let
+  logPrefix = "services.prometheus.exporter.php-fpm";
+  cfg = config.services.prometheus.exporters.php-fpm;
+in {
+  port = 9253;
+  extraOpts = {
+    package = lib.mkPackageOptionMD pkgs "prometheus-php-fpm-exporter" {};
+
+    telemetryPath = lib.mkOption {
+      type = lib.types.str;
+      default = "/metrics";
+      description = lib.mdDoc ''
+        Path under which to expose metrics.
+      '';
+    };
+
+    environmentFile = lib.mkOption {
+      type = lib.types.nullOr lib.types.path;
+      default = null;
+      example = "/root/prometheus-php-fpm-exporter.env";
+      description = lib.mdDoc ''
+        Environment file as defined in {manpage}`systemd.exec(5)`.
+
+        Secrets may be passed to the service without adding them to the
+        world-readable Nix store, by specifying placeholder variables as
+        the option value in Nix and setting these variables accordingly in the
+        environment file.
+
+        Environment variables from this file will be interpolated into the
+        config file using envsubst with this syntax:
+        `$ENVIRONMENT ''${VARIABLE}`
+
+        For variables to use see [options and defaults](https://github.com/hipages/php-fpm_exporter#options-and-defaults).
+
+        The main use is to set the PHP_FPM_SCRAPE_URI that indicate how to connect to PHP-FPM process.
+
+        ```
+          # Content of the environment file
+          PHP_FPM_SCRAPE_URI="unix:///tmp/php.sock;/status"
+        ```
+
+        Note that this file needs to be available on the host on which
+        this exporter is running.
+      '';
+    };
+  };
+
+  serviceOpts = {
+    serviceConfig = {
+      EnvironmentFile = lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
+      ExecStart = ''
+        ${lib.getExe cfg.package} server \
+          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
+          --web.telemetry-path ${cfg.telemetryPath} \
+          ${lib.concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+    };
+  };
+}