1 { config, lib, pkgs, options, ... }:
3 cfg = config.services.prometheus.exporters.mysqld;
4 inherit (lib) types mkOption mkIf mkForce cli concatStringsSep optionalString escapeShellArgs;
8 telemetryPath = mkOption {
12 Path under which to expose metrics.
16 runAsLocalSuperUser = mkOption {
20 Whether to run the exporter as {option}`services.mysql.user`.
24 configFile = mkOption {
26 example = "/var/lib/prometheus-mysqld-exporter.cnf";
28 Path to the services config file.
30 See <https://github.com/prometheus/mysqld_exporter#running> for more information about
31 the available options.
34 Please do not store this file in the nix store if you choose to include any credentials here,
35 as it would be world-readable.
43 DynamicUser = !cfg.runAsLocalSuperUser;
44 User = mkIf cfg.runAsLocalSuperUser (mkForce config.services.mysql.user);
45 LoadCredential = mkIf (cfg.configFile != null) (mkForce ("config:" + cfg.configFile));
46 ExecStart = concatStringsSep " " [
47 "${pkgs.prometheus-mysqld-exporter}/bin/mysqld_exporter"
48 "--web.listen-address=${cfg.listenAddress}:${toString cfg.port}"
49 "--web.telemetry-path=${cfg.telemetryPath}"
50 (optionalString (cfg.configFile != null) ''--config.my-cnf=''${CREDENTIALS_DIRECTORY}/config'')
51 (escapeShellArgs cfg.extraFlags)
53 RestrictAddressFamilies = [
54 # The exporter can be configured to talk to a local mysql server via a unix socket.