diff options
author | Martin Fischer <martin@push-f.com> | 2025-08-30 19:27:25 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-08-30 20:03:15 +0200 |
commit | 80a98992584487a389900ea9e78963c01ea3d812 (patch) | |
tree | e5b254c6d7956e2d181375847904766b2a3af586 /nixos/hosts/tente/exporters.nix | |
parent | 0c1ab2a61849a92f8df4170b934a3cdc68ec98da (diff) |
refactor: make Prometheus & Loki config reusable
Diffstat (limited to 'nixos/hosts/tente/exporters.nix')
-rw-r--r-- | nixos/hosts/tente/exporters.nix | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/nixos/hosts/tente/exporters.nix b/nixos/hosts/tente/exporters.nix new file mode 100644 index 0000000..1ed53e5 --- /dev/null +++ b/nixos/hosts/tente/exporters.nix @@ -0,0 +1,55 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.exporters; +in +{ + options.exporters = { + sqlExporterPort = lib.mkOption { + type = lib.types.int; + }; + }; + + imports = [ + <top/shared/prometheus-sql-exporter/service.nix> + ]; + + config = { + services.prometheus-sql-exporter = { + enable = true; + port = cfg.sqlExporterPort; + config = { + target = { + # 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 = [ + { + 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"; + } + ]; + } + ]; + }; + }; + + monitoring.prometheusScrapeConfigs = [ + { + job_name = "sql"; + static_configs = [{ + targets = [ "localhost:${toString cfg.sqlExporterPort}" ]; + }]; + } + ]; + }; +} |