diff options
-rw-r--r-- | nixos/hosts/tente/exporters.nix | 19 | ||||
-rw-r--r-- | nixos/shared/postgres-collectors.nix | 22 |
2 files changed, 25 insertions, 16 deletions
diff --git a/nixos/hosts/tente/exporters.nix b/nixos/hosts/tente/exporters.nix index 1ed53e5..1c03c35 100644 --- a/nixos/hosts/tente/exporters.nix +++ b/nixos/hosts/tente/exporters.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, ... }: let + helpers = import <top/shared/postgres-collectors.nix> { inherit config lib pkgs; }; cfg = config.exporters; in { @@ -23,23 +24,9 @@ in # This URL should be postgresql:///postgres?host=/run/postgresql # but sql_exporter uses xo/dburl which isn't spec-compliant: https://github.com/xo/dburl/issues/46 data_source_name = "postgresql:/run/postgresql:/postgres"; - collectors = ["db-sizes"]; + collectors = helpers.collectorNames; }; - collectors = [ - { - collector_name = "db-sizes"; - metrics = [ - { - metric_name = "pg_db_size_bytes"; - help = "disk space used by the database"; - type = "gauge"; - key_labels = ["database_name"]; - values = ["size"]; - query = "SELECT datname AS database_name, pg_database_size(datname) as size from pg_database"; - } - ]; - } - ]; + collectors = helpers.collectors; }; }; diff --git a/nixos/shared/postgres-collectors.nix b/nixos/shared/postgres-collectors.nix new file mode 100644 index 0000000..fd44cb0 --- /dev/null +++ b/nixos/shared/postgres-collectors.nix @@ -0,0 +1,22 @@ +# collectors for the prometheus-sql-exporter +{ config, lib, pkgs, ... }: + +{ + collectorNames = ["db-sizes"]; + + collectors = [ + { + collector_name = "db-sizes"; + metrics = [ + { + metric_name = "pg_db_size_bytes"; + help = "disk space used by the database"; + type = "gauge"; + key_labels = ["database_name"]; + values = ["size"]; + query = "SELECT datname AS database_name, pg_database_size(datname) as size from pg_database"; + } + ]; + } + ]; +} |