Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
be87d98060
|
@@ -8,6 +8,7 @@ in {
|
|||||||
./matrix-synapse.nix
|
./matrix-synapse.nix
|
||||||
./mysqld.nix
|
./mysqld.nix
|
||||||
./postgres.nix
|
./postgres.nix
|
||||||
|
./dibbler.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
services.prometheus = {
|
services.prometheus = {
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.services.prometheus.exporters.sql;
|
||||||
|
configFile =
|
||||||
|
if cfg.configFile != null then
|
||||||
|
cfg.configFile
|
||||||
|
else
|
||||||
|
let
|
||||||
|
nameInline = lib.mapAttrsToList (k: v: v // { name = k; });
|
||||||
|
renameStartupSql = j: removeAttrs (j // { startup_sql = j.startupSql; }) [ "startupSql" ];
|
||||||
|
configuration = {
|
||||||
|
jobs = map renameStartupSql (
|
||||||
|
nameInline (lib.mapAttrs (k: v: (v // { queries = nameInline v.queries; })) cfg.configuration.jobs)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
in
|
||||||
|
builtins.toFile "config.yaml" (builtins.toJSON configuration);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
sops.secrets."config/postgresql_dibbler_password" = { };
|
||||||
|
|
||||||
|
services.prometheus.scrapeConfigs = [
|
||||||
|
{
|
||||||
|
job_name = "sql_exporter";
|
||||||
|
scrape_interval = "1m";
|
||||||
|
scheme = "http";
|
||||||
|
|
||||||
|
static_configs = [
|
||||||
|
{
|
||||||
|
targets = [ "localhost:9237" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
services.prometheus.exporters.sql = {
|
||||||
|
enable = true;
|
||||||
|
configuration = {
|
||||||
|
jobs.dibbler = {
|
||||||
|
interval = "1m";
|
||||||
|
|
||||||
|
queries."daily_purchase_sum" = {
|
||||||
|
help = "Sum of purchases for the current day.";
|
||||||
|
labels = [ "thing" ];
|
||||||
|
values = [ "sum" ];
|
||||||
|
query = "SELECT SUM(price) FROM purchases GROUP BY DATE(time) ORDER BY DATE(time) DESC LIMIT 1";
|
||||||
|
};
|
||||||
|
|
||||||
|
queries."total_purchase_sum" = {
|
||||||
|
help = "Sum of all purchases.";
|
||||||
|
labels = [ "thing" ];
|
||||||
|
values = [ "sum" ];
|
||||||
|
query = "SELECT SUM(price) FROM purchases";
|
||||||
|
};
|
||||||
|
|
||||||
|
queries."total_stock_value" = {
|
||||||
|
help = "The value of all stock in dibbler.";
|
||||||
|
labels = [ "thing" ];
|
||||||
|
values = [ "sum" ];
|
||||||
|
query = "SELECT SUM(price * stock) FROM products";
|
||||||
|
};
|
||||||
|
|
||||||
|
queries."user_credit_sum" = {
|
||||||
|
help = "The sum of all user credit.";
|
||||||
|
labels = [ "thing" ];
|
||||||
|
values = [ "sum" ];
|
||||||
|
query = "SELECT SUM(credit) FROM users";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services."prometheus-sql-exporter".serviceConfig = {
|
||||||
|
RuntimeDirectory = "prometheus-sql-exporter";
|
||||||
|
LoadCredential = "postgresql_dibbler_password:${
|
||||||
|
config.sops.secrets."config/postgresql_dibbler_password".path
|
||||||
|
}";
|
||||||
|
ExecStartPre = ''
|
||||||
|
|${lib.getExe pkgs.jq} \
|
||||||
|
--null-input \
|
||||||
|
--compact-output \
|
||||||
|
--slurpfile config '${configFile}' \
|
||||||
|
--rawfile pw '%d/postgresql_dibbler_password' \
|
||||||
|
--from-file '${pkgs.writeText "prometheus-sql-exec-start-jq-filter" ''
|
||||||
|
("postgres://pvv_vv:\($pw | gsub("\n"; ""))@postgres.pvv.ntnu.no") as $pg_uri
|
||||||
|
| $config[0]
|
||||||
|
| .jobs[0].connections[0] = $pg_uri
|
||||||
|
''}' > /run/prometheus-sql-exporter/config.yaml
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
config:
|
config:
|
||||||
mysqld_exporter_password: ENC[AES256_GCM,data:I9K+QMqaN3FOOVKzeOR9Q6UERStXX0P8WEHyN1jzzbM=,iv:UxvIdlfAyJvNuxPkU4+guKPa0fiD0vVLzHOTYktcmso=,tag:ltnIqEwESYx9HBu8UN0ZLw==,type:str]
|
mysqld_exporter_password: ENC[AES256_GCM,data:I9K+QMqaN3FOOVKzeOR9Q6UERStXX0P8WEHyN1jzzbM=,iv:UxvIdlfAyJvNuxPkU4+guKPa0fiD0vVLzHOTYktcmso=,tag:ltnIqEwESYx9HBu8UN0ZLw==,type:str]
|
||||||
|
postgresql_dibbler_password: ENC[AES256_GCM,data:wP4CVz9qRE3CJrblWWYqOIkcH3LM5H81,iv:j8zr1TRNlPPqIppYlWhDoKlL7m2Ph2wQlU6bvFj8R9A=,tag:Cfp8zbYkoLqI7DTDpOBlJw==,type:str]
|
||||||
keys:
|
keys:
|
||||||
grafana:
|
grafana:
|
||||||
secret_key: ENC[AES256_GCM,data:+WoAJbDBEgKs0RoHT+7oEELAVQ+/2Xt+5RTMSXg23moCqVRx+Gzll9P5Drw=,iv:AkRn/Y20iEe5i1T+84wAgLCTFtAox2G3giyawAkltAw=,tag:BZbt5Wb5lYLIJBm/pfP4GQ==,type:str]
|
secret_key: ENC[AES256_GCM,data:+WoAJbDBEgKs0RoHT+7oEELAVQ+/2Xt+5RTMSXg23moCqVRx+Gzll9P5Drw=,iv:AkRn/Y20iEe5i1T+84wAgLCTFtAox2G3giyawAkltAw=,tag:BZbt5Wb5lYLIJBm/pfP4GQ==,type:str]
|
||||||
@@ -72,8 +73,8 @@ sops:
|
|||||||
dC9meDZlc3d3aUJEVjc4REF0Y1BLcGcK79LbJzc5KVgEgyJR11crGuX8YcVoJBbT
|
dC9meDZlc3d3aUJEVjc4REF0Y1BLcGcK79LbJzc5KVgEgyJR11crGuX8YcVoJBbT
|
||||||
Fin7Zoon06L7qx0Zw5u27wV7RKMnYT7hOMiWs6660ZTLcYJ5M1aEZQ==
|
Fin7Zoon06L7qx0Zw5u27wV7RKMnYT7hOMiWs6660ZTLcYJ5M1aEZQ==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2025-03-16T20:08:18Z"
|
lastmodified: "2026-06-07T12:51:04Z"
|
||||||
mac: ENC[AES256_GCM,data:C2tpWppc13jKJq5d4nmAKQOaNWHm27TKwxAxm1fi2lejN1lqUaoz5bHfTBA7MfaWvuP5uZnfbtG32eeu48mnlWpo58XRUFFecAhb9JUpW9s5IR3/nbzLNkGU7H5C0oWPrxI4thd+bAVduIgBjjFyGj1pe6J9db3c0yUWRwNlwGU=,iv:YpoQ4psiFYOWLGipxv1QvRvr034XFsyn2Bhyy39HmOo=,tag:ByiCWygFC/VokVTbdLoLgg==,type:str]
|
mac: ENC[AES256_GCM,data:otGwzc3Bme1PGRU4zWRRf3kmAf5EDjT8sPkDK/zDrO0ve+d3x99Qls4DBZV8G6FsFtUXbeKVo70I5VpqUgaIef+nyMl6zzWkW1wpbKIBYjh5fkaP0xxhLnw+shrB088PAXT0wkP7hJBLO0ZJgTrpprJKhmeqVj2HEXBSJ1wSjk8=,iv:cjqtdbWBVLUfpQdykb3vKDKa/VC/kGBybwYtG/eStqc=,tag:remOj4bX/H/LlAPgcXHAdA==,type:str]
|
||||||
pgp:
|
pgp:
|
||||||
- created_at: "2026-05-20T17:35:58Z"
|
- created_at: "2026-05-20T17:35:58Z"
|
||||||
enc: |-
|
enc: |-
|
||||||
@@ -96,4 +97,4 @@ sops:
|
|||||||
-----END PGP MESSAGE-----
|
-----END PGP MESSAGE-----
|
||||||
fp: F7D37890228A907440E1FD4846B9228E814A2AAC
|
fp: F7D37890228A907440E1FD4846B9228E814A2AAC
|
||||||
unencrypted_suffix: _unencrypted
|
unencrypted_suffix: _unencrypted
|
||||||
version: 3.9.4
|
version: 3.12.2
|
||||||
|
|||||||
Reference in New Issue
Block a user