blob: 1ed53e59021f4bd2df197e1ff45abf4bb19b794f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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}" ];
}];
}
];
};
}
|