summary refs log tree commit diff
path: root/nixos/tests/prometheus-exporters.nix
diff options
context:
space:
mode:
authorJustinas Stankevicius <justinas@justinas.org>2020-08-06 09:56:35 +0300
committerMaximilian Bosch <maximilian@mbosch.me>2020-11-06 16:35:38 +0100
commitd447c2413cbace4fdcbeb6a364bc08d310309c4e (patch)
tree3523abef3fd6c8f4c081de238e6ad1e0b678cb0e /nixos/tests/prometheus-exporters.nix
parent01762fec0ab7576e3b371eda3dd3fd576e640798 (diff)
downloadnixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar.gz
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar.bz2
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar.lz
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar.xz
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.tar.zst
nixpkgs-d447c2413cbace4fdcbeb6a364bc08d310309c4e.zip
nixos/prometheus-sql-exporter: new module
Diffstat (limited to 'nixos/tests/prometheus-exporters.nix')
-rw-r--r--nixos/tests/prometheus-exporters.nix44
1 files changed, 44 insertions, 0 deletions
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index ad2fff2b01f..a7e946f5c46 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -578,6 +578,50 @@ let
       '';
     };
 
+    sql = {
+      exporterConfig = {
+        configuration.jobs.points = {
+          interval = "1m";
+          connections = [
+            "postgres://prometheus-sql-exporter@/data?host=/run/postgresql&sslmode=disable"
+          ];
+          queries = {
+            points = {
+              labels = [ "name" ];
+              help = "Amount of points accumulated per person";
+              values = [ "amount" ];
+              query = "SELECT SUM(amount) as amount, name FROM points GROUP BY name";
+            };
+          };
+        };
+        enable = true;
+        user = "postgres";
+      };
+      metricProvider = {
+        services.postgresql = {
+          enable = true;
+          initialScript = builtins.toFile "init.sql" ''
+            CREATE DATABASE data;
+            \c data;
+            CREATE TABLE points (amount INT, name TEXT);
+            INSERT INTO points(amount, name) VALUES (1, 'jack');
+            INSERT INTO points(amount, name) VALUES (2, 'jill');
+            INSERT INTO points(amount, name) VALUES (3, 'jack');
+
+            CREATE USER "prometheus-sql-exporter";
+            GRANT ALL PRIVILEGES ON DATABASE data TO "prometheus-sql-exporter";
+            GRANT SELECT ON points TO "prometheus-sql-exporter";
+          '';
+        };
+        systemd.services.prometheus-sql-exporter.after = [ "postgresql.service" ];
+      };
+      exporterTest = ''
+        wait_for_unit("prometheus-sql-exporter.service")
+        wait_for_open_port(9237)
+        succeed("curl http://localhost:9237/metrics | grep -c 'sql_points{' | grep -q 2")
+      '';
+    };
+
     surfboard = {
       exporterConfig = {
         enable = true;