mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-19 03:29:17 +03:00
Merge pull request #240394 from gaelreyrol/prometheus-php-fpm-exporter-init
prometheus-php-fpm-exporter: init at 2.2.0
This commit is contained in:
commit
958fb96b56
@ -82,6 +82,8 @@
|
||||
|
||||
- The module `services.calibre-server` has new options to configure the `host`, `port`, `auth.enable`, `auth.mode` and `auth.userDb` path, see [#216497](https://github.com/NixOS/nixpkgs/pull/216497/) for more details.
|
||||
|
||||
- `services.prometheus.exporters` has a new [exporter](https://github.com/hipages/php-fpm_exporter) to monitor PHP-FPM processes, see [#240394](https://github.com/NixOS/nixpkgs/pull/240394) for more details.
|
||||
|
||||
## Nixpkgs internals {#sec-release-23.11-nixpkgs-internals}
|
||||
|
||||
- The `qemu-vm.nix` module by default now identifies block devices via
|
||||
|
@ -56,6 +56,7 @@ let
|
||||
"nut"
|
||||
"openldap"
|
||||
"openvpn"
|
||||
"php-fpm"
|
||||
"pihole"
|
||||
"postfix"
|
||||
"postgres"
|
||||
|
@ -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}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
let
|
||||
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
|
||||
inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge
|
||||
removeSuffix replaceStrings singleton splitString;
|
||||
removeSuffix replaceStrings singleton splitString makeBinPath;
|
||||
|
||||
/*
|
||||
* The attrset `exporterTests` contains one attribute
|
||||
@ -914,6 +914,47 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
php-fpm = {
|
||||
nodeName = "php_fpm";
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
environmentFile = pkgs.writeTextFile {
|
||||
name = "/tmp/prometheus-php-fpm-exporter.env";
|
||||
text = ''
|
||||
PHP_FPM_SCRAPE_URI="tcp://127.0.0.1:9000/status"
|
||||
'';
|
||||
};
|
||||
};
|
||||
metricProvider = {
|
||||
users.users."php-fpm-exporter" = {
|
||||
isSystemUser = true;
|
||||
group = "php-fpm-exporter";
|
||||
};
|
||||
users.groups."php-fpm-exporter" = {};
|
||||
services.phpfpm.pools."php-fpm-exporter" = {
|
||||
user = "php-fpm-exporter";
|
||||
group = "php-fpm-exporter";
|
||||
settings = {
|
||||
"pm" = "dynamic";
|
||||
"pm.max_children" = 32;
|
||||
"pm.max_requests" = 500;
|
||||
"pm.start_servers" = 2;
|
||||
"pm.min_spare_servers" = 2;
|
||||
"pm.max_spare_servers" = 5;
|
||||
"pm.status_path" = "/status";
|
||||
"listen" = "127.0.0.1:9000";
|
||||
"listen.allowed_clients" = "127.0.0.1";
|
||||
};
|
||||
phpEnv."PATH" = makeBinPath [ pkgs.php ];
|
||||
};
|
||||
};
|
||||
exporterTest = ''
|
||||
wait_for_unit("phpfpm-php-fpm-exporter.service")
|
||||
wait_for_unit("prometheus-php-fpm-exporter.service")
|
||||
succeed("curl -sSf http://localhost:9253/metrics | grep 'phpfpm_up{.*} 1'")
|
||||
'';
|
||||
};
|
||||
|
||||
postfix = {
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
|
59
pkgs/servers/monitoring/prometheus/php-fpm-exporter.nix
Normal file
59
pkgs/servers/monitoring/prometheus/php-fpm-exporter.nix
Normal file
@ -0,0 +1,59 @@
|
||||
{ lib
|
||||
, buildGoModule
|
||||
, fetchFromGitHub
|
||||
, makeWrapper
|
||||
, installShellFiles
|
||||
, getent
|
||||
, nix-update-script
|
||||
, testers
|
||||
, prometheus-php-fpm-exporter
|
||||
}:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "php-fpm_exporter";
|
||||
version = "2.2.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "hipages";
|
||||
repo = pname;
|
||||
rev = "v${version}";
|
||||
hash = "sha256-ggrFnyEdGBoZVh4dHMw+7RUm8nJ1hJXo/fownO3wvzE=";
|
||||
};
|
||||
|
||||
vendorHash = "sha256-OK36tHkBtosdfEWFPYMtlbzCkh5cF35NBWYyJrb9fwg= ";
|
||||
|
||||
nativeBuildInputs = [ makeWrapper installShellFiles ];
|
||||
|
||||
ldflags = [
|
||||
"-X main.version=${version}"
|
||||
];
|
||||
|
||||
preFixup = ''
|
||||
wrapProgram "$out/bin/php-fpm_exporter" \
|
||||
--prefix PATH ":" "${lib.makeBinPath [ getent ]}"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
installShellCompletion --cmd php-fpm_exporter \
|
||||
--bash <($out/bin/php-fpm_exporter completion bash) \
|
||||
--fish <($out/bin/php-fpm_exporter completion fish) \
|
||||
--zsh <($out/bin/php-fpm_exporter completion zsh)
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
updateScript = nix-update-script { };
|
||||
tests = testers.testVersion {
|
||||
inherit version;
|
||||
package = prometheus-php-fpm-exporter;
|
||||
command = "php-fpm_exporter version";
|
||||
};
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
homepage = "https://github.com/hipages/php-fpm_exporter";
|
||||
description = "A prometheus exporter for PHP-FPM.";
|
||||
license = licenses.asl20;
|
||||
maintainers = with maintainers; [ gaelreyrol ];
|
||||
mainProgram = "php-fpm_exporter";
|
||||
};
|
||||
}
|
@ -26487,6 +26487,7 @@ with pkgs;
|
||||
prometheus-nut-exporter = callPackage ../servers/monitoring/prometheus/nut-exporter.nix { };
|
||||
prometheus-openldap-exporter = callPackage ../servers/monitoring/prometheus/openldap-exporter.nix { } ;
|
||||
prometheus-openvpn-exporter = callPackage ../servers/monitoring/prometheus/openvpn-exporter.nix { };
|
||||
prometheus-php-fpm-exporter = callPackage ../servers/monitoring/prometheus/php-fpm-exporter.nix { };
|
||||
prometheus-pihole-exporter = callPackage ../servers/monitoring/prometheus/pihole-exporter.nix { };
|
||||
prometheus-postfix-exporter = callPackage ../servers/monitoring/prometheus/postfix-exporter.nix { };
|
||||
prometheus-postgres-exporter = callPackage ../servers/monitoring/prometheus/postgres-exporter.nix { };
|
||||
|
Loading…
Reference in New Issue
Block a user