1 { config, lib, pkgs, options, ... }:
3 cfg = config.services.prometheus.exporters.sql;
12 options = with types; {
14 type = attrsOf (submodule jobOptions);
16 description = "An attrset of metrics scraping jobs to run.";
21 options = with types; {
25 How often to run this job, specified in
26 [Go duration](https://golang.org/pkg/time/#ParseDuration) format.
29 connections = mkOption {
31 description = "A list of connection strings of the SQL servers to scrape metrics from";
33 startupSql = mkOption {
36 description = "A list of SQL statements to execute once after making a connection.";
39 type = attrsOf (submodule queryOptions);
40 description = "SQL queries to run.";
45 options = with types; {
49 description = "A human-readable description of this metric.";
54 description = "A set of columns that will be used as Prometheus labels.";
58 description = "The SQL query to run.";
62 description = "A set of columns that will be used as values of this metric.";
68 if cfg.configFile != null
72 nameInline = mapAttrsToList (k: v: v // { name = k; });
73 renameStartupSql = j: removeAttrs (j // { startup_sql = j.startupSql; }) [ "startupSql" ];
75 jobs = map renameStartupSql
76 (nameInline (mapAttrs (k: v: (v // { queries = nameInline v.queries; })) cfg.configuration.jobs));
79 builtins.toFile "config.yaml" (builtins.toJSON configuration);
83 configFile = mkOption {
84 type = with types; nullOr path;
87 Path to configuration file.
90 configuration = mkOption {
91 type = with types; nullOr (submodule cfgOptions);
94 Exporter configuration as nix attribute set. Mutually exclusive with 'configFile' option.
103 ${pkgs.prometheus-sql-exporter}/bin/sql_exporter \
104 -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
105 -config.file ${configFile} \
106 ${concatStringsSep " \\\n " cfg.extraFlags}
108 RestrictAddressFamilies = [
109 # Need AF_UNIX to collect data