From 13a9af64bc60192ed60a8047ee7967b8c87629c7 Mon Sep 17 00:00:00 2001 From: Vegard Bieker Matthey Date: Sun, 7 Jun 2026 03:30:23 +0200 Subject: [PATCH] export and scrape dibbler prometheus stats --- .../monitoring/prometheus/default.nix | 1 + .../monitoring/prometheus/dibbler.nix | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 hosts/ildkule/services/monitoring/prometheus/dibbler.nix diff --git a/hosts/ildkule/services/monitoring/prometheus/default.nix b/hosts/ildkule/services/monitoring/prometheus/default.nix index e71a3b9..72a83b5 100644 --- a/hosts/ildkule/services/monitoring/prometheus/default.nix +++ b/hosts/ildkule/services/monitoring/prometheus/default.nix @@ -8,6 +8,7 @@ in { ./matrix-synapse.nix ./mysqld.nix ./postgres.nix + ./dibbler.nix ]; services.prometheus = { diff --git a/hosts/ildkule/services/monitoring/prometheus/dibbler.nix b/hosts/ildkule/services/monitoring/prometheus/dibbler.nix new file mode 100644 index 0000000..ca4e12d --- /dev/null +++ b/hosts/ildkule/services/monitoring/prometheus/dibbler.nix @@ -0,0 +1,52 @@ +{ ... }: +{ + 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"; + connections = [ + "postgres://pvv_vv:WP97&amDp&*gfhg3TyR8@postgres.pvv.ntnu.no" + ]; + + 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"; + }; + }; + }; + }; +}