diff options
author | h7x4 <h7x4@nani.wtf> | 2023-07-08 00:01:45 +0200 |
---|---|---|
committer | h7x4 <h7x4@nani.wtf> | 2023-08-13 19:46:30 +0200 |
commit | 8981783b6071234bcc7fb6dc1b2c0ad3f833797b (patch) | |
tree | a6428760439c92b1a985e2ccea72c6f40e3755a3 /nixos/modules/services/monitoring | |
parent | 0829d0f7efe3c0c461e00f481b37f343f2165e08 (diff) | |
download | nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar.gz nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar.bz2 nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar.lz nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar.xz nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.tar.zst nixlib-8981783b6071234bcc7fb6dc1b2c0ad3f833797b.zip |
services/prometheus/exporters: add mysqld
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters.nix | 7 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/prometheus/exporters/mysqld.nix | 60 |
2 files changed, 67 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 397125b51230..66cc39876e91 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -49,6 +49,7 @@ let "mikrotik" "minio" "modemmanager" + "mysqld" "nextcloud" "nginx" "nginxlog" @@ -296,6 +297,12 @@ in or 'services.prometheus.exporters.mail.configFile'. ''; } { + assertion = cfg.mysqld.runAsLocalSuperUser -> config.services.mysql.enable; + message = '' + The exporter is configured to run as 'services.mysql.user', but + 'services.mysql.enable' is set to false. + ''; + } { assertion = cfg.sql.enable -> ( (cfg.sql.configFile == null) != (cfg.sql.configuration == null) ); diff --git a/nixos/modules/services/monitoring/prometheus/exporters/mysqld.nix b/nixos/modules/services/monitoring/prometheus/exporters/mysqld.nix new file mode 100644 index 000000000000..849c514de681 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/mysqld.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, options }: +let + cfg = config.services.prometheus.exporters.mysqld; + inherit (lib) types mkOption mdDoc mkIf mkForce cli concatStringsSep optionalString escapeShellArgs; +in { + port = 9104; + extraOpts = { + telemetryPath = mkOption { + type = types.str; + default = "/metrics"; + description = mdDoc '' + Path under which to expose metrics. + ''; + }; + + runAsLocalSuperUser = mkOption { + type = types.bool; + default = false; + description = mdDoc '' + Whether to run the exporter as {option}`services.mysql.user`. + ''; + }; + + configFile = mkOption { + type = types.path; + example = "/var/lib/prometheus-mysqld-exporter.cnf"; + description = mdDoc '' + Path to the services config file. + + See <https://github.com/prometheus/mysqld_exporter#running> for more information about + the available options. + + ::: {.warn} + Please do not store this file in the nix store if you choose to include any credentials here, + as it would be world-readable. + ::: + ''; + }; + }; + + serviceOpts = { + serviceConfig = { + DynamicUser = !cfg.runAsLocalSuperUser; + User = mkIf cfg.runAsLocalSuperUser (mkForce config.services.mysql.user); + LoadCredential = mkIf (cfg.configFile != null) (mkForce ("config:" + cfg.configFile)); + ExecStart = concatStringsSep " " [ + "${pkgs.prometheus-mysqld-exporter}/bin/mysqld_exporter" + "--web.listen-address=${cfg.listenAddress}:${toString cfg.port}" + "--web.telemetry-path=${cfg.telemetryPath}" + (optionalString (cfg.configFile != null) ''--config.my-cnf=''${CREDENTIALS_DIRECTORY}/config'') + (escapeShellArgs cfg.extraFlags) + ]; + RestrictAddressFamilies = [ + # The exporter can be configured to talk to a local mysql server via a unix socket. + "AF_UNIX" + ]; + }; + }; +} + |