services/prometheus/exporters: add mysqld
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This commit is contained in:
parent
0829d0f7ef
commit
8981783b60
|
@ -18,6 +18,8 @@
|
|||
|
||||
- [Anuko Time Tracker](https://github.com/anuko/timetracker), a simple, easy to use, open source time tracking system. Available as [services.anuko-time-tracker](#opt-services.anuko-time-tracker.enable).
|
||||
|
||||
- [Prometheus MySQL exporter](https://github.com/prometheus/mysqld_exporter), a MySQL server exporter for Prometheus. Available as [services.prometheus.exporters.mysqld](#opt-services.prometheus.exporters.mysqld.enable).
|
||||
|
||||
- [sitespeed-io](https://sitespeed.io), a tool that can generate metrics (timings, diagnostics) for websites. Available as [services.sitespeed-io](#opt-services.sitespeed-io.enable).
|
||||
|
||||
- [Apache Guacamole](https://guacamole.apache.org/), a cross-platform, clientless remote desktop gateway. Available as [services.guacamole-server](#opt-services.guacamole-server.enable) and [services.guacamole-client](#opt-services.guacamole-client.enable) services.
|
||||
|
|
|
@ -49,6 +49,7 @@ let
|
|||
"mikrotik"
|
||||
"minio"
|
||||
"modemmanager"
|
||||
"mysqld"
|
||||
"nextcloud"
|
||||
"nginx"
|
||||
"nginxlog"
|
||||
|
@ -295,6 +296,12 @@ in
|
|||
Please specify either 'services.prometheus.exporters.mail.configuration'
|
||||
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)
|
||||
|
|
|
@ -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"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in a new issue