Merge pull request #94673 from justinas/prom-sql-exporter
prometheus-sql-exporter: init at 0.3.0
This commit is contained in:
@@ -609,6 +609,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 = "prometheus-sql-exporter";
|
||||
};
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user