summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/monitoring.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/hosts/tente/monitoring.nix')
-rw-r--r--nixos/hosts/tente/monitoring.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/nixos/hosts/tente/monitoring.nix b/nixos/hosts/tente/monitoring.nix
index 41c59f3..b9c806e 100644
--- a/nixos/hosts/tente/monitoring.nix
+++ b/nixos/hosts/tente/monitoring.nix
@@ -17,8 +17,15 @@ in
prometheusNodeExporterPort = lib.mkOption {
type = lib.types.int;
};
+ prometheusSqlExporterPort = lib.mkOption {
+ type = lib.types.int;
+ };
};
+ imports = [
+ <top/shared/prometheus-sql-exporter/service.nix>
+ ];
+
config = {
services.grafana = {
enable = true;
@@ -57,6 +64,12 @@ in
targets = [ "localhost:${toString cfg.prometheusNodeExporterPort}" ];
}];
}
+ {
+ job_name = "sql";
+ static_configs = [{
+ targets = [ "localhost:${toString cfg.prometheusSqlExporterPort}" ];
+ }];
+ }
];
exporters.node = {
@@ -66,6 +79,34 @@ in
};
};
+ services.prometheus-sql-exporter = {
+ enable = true;
+ port = cfg.prometheusSqlExporterPort;
+ 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";
+ }
+ ];
+ }
+ ];
+ };
+ };
+
services.loki = {
enable = true;
configuration = {