9 cfg = config.services.prometheus.exporters.sql;
18 options = with types; {
20 type = attrsOf (submodule jobOptions);
22 description = "An attrset of metrics scraping jobs to run.";
27 options = with types; {
31 How often to run this job, specified in
32 [Go duration](https://golang.org/pkg/time/#ParseDuration) format.
35 connections = mkOption {
37 description = "A list of connection strings of the SQL servers to scrape metrics from";
39 startupSql = mkOption {
42 description = "A list of SQL statements to execute once after making a connection.";
45 type = attrsOf (submodule queryOptions);
46 description = "SQL queries to run.";
51 options = with types; {
55 description = "A human-readable description of this metric.";
60 description = "A set of columns that will be used as Prometheus labels.";
64 description = "The SQL query to run.";
68 description = "A set of columns that will be used as values of this metric.";
74 if cfg.configFile != null then
78 nameInline = mapAttrsToList (k: v: v // { name = k; });
79 renameStartupSql = j: removeAttrs (j // { startup_sql = j.startupSql; }) [ "startupSql" ];
81 jobs = map renameStartupSql (
82 nameInline (mapAttrs (k: v: (v // { queries = nameInline v.queries; })) cfg.configuration.jobs)
86 builtins.toFile "config.yaml" (builtins.toJSON configuration);
90 configFile = mkOption {
91 type = with types; nullOr path;
94 Path to configuration file.
97 configuration = mkOption {
98 type = with types; nullOr (submodule cfgOptions);
101 Exporter configuration as nix attribute set. Mutually exclusive with 'configFile' option.
110 ${pkgs.prometheus-sql-exporter}/bin/sql_exporter \
111 -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
112 -config.file ${configFile} \
113 ${concatStringsSep " \\\n " cfg.extraFlags}
115 RestrictAddressFamilies = [
116 # Need AF_UNIX to collect data