1 { system ? builtins.currentSystem
3 , pkgs ? import ../.. { inherit system config; }
7 inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
8 inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge
9 removeSuffix replaceChars singleton splitString;
12 * The attrset `exporterTests` contains one attribute
13 * for each exporter test. Each of these attributes
14 * is expected to be an attrset containing:
17 * this attribute set contains config for the exporter itself
20 * this attribute set contains test instructions
22 * `metricProvider` (optional)
23 * this attribute contains additional machine config
25 * `nodeName` (optional)
26 * override an incompatible testnode name
29 * exporterTests.<exporterName> = {
34 * services.<metricProvider>.enable = true;
37 * wait_for_unit("prometheus-<exporterName>-exporter.service")
38 * wait_for_open_port(1234)
39 * succeed("curl -sSf 'localhost:1234/metrics'")
43 * # this would generate the following test config:
45 * nodes.<exporterName> = {
46 * services.prometheus.<exporterName> = {
49 * services.<metricProvider>.enable = true;
53 * <exporterName>.start()
54 * <exporterName>.wait_for_unit("prometheus-<exporterName>-exporter.service")
55 * <exporterName>.wait_for_open_port(1234)
56 * <exporterName>.succeed("curl -sSf 'localhost:1234/metrics'")
57 * <exporterName>.shutdown()
67 services.apcupsd.enable = true;
70 wait_for_unit("apcupsd.service")
71 wait_for_open_port(3551)
72 wait_for_unit("prometheus-apcupsd-exporter.service")
73 wait_for_open_port(9162)
74 succeed("curl -sSf http://localhost:9162/metrics | grep 'apcupsd_info'")
81 artiUsername = "artifactory-username";
82 artiPassword = "artifactory-password";
85 wait_for_unit("prometheus-artifactory-exporter.service")
86 wait_for_open_port(9531)
88 "curl -sSf http://localhost:9531/metrics | grep 'artifactory_up'"
98 services.bind.enable = true;
99 services.bind.extraConfig = ''
100 statistics-channels {
101 inet 127.0.0.1 port 8053 allow { localhost; };
106 wait_for_unit("prometheus-bind-exporter.service")
107 wait_for_open_port(9119)
109 "curl -sSf http://localhost:9119/metrics | grep 'bind_query_recursions_total 0'"
119 services.bird2.enable = true;
120 services.bird2.config = ''
123 protocol kernel MyObviousTestString {
135 wait_for_unit("prometheus-bird-exporter.service")
136 wait_for_open_port(9324)
138 "curl -sSf http://localhost:9324/metrics | grep 'MyObviousTestString'"
146 rpcUser = "bitcoinrpc";
147 rpcPasswordFile = pkgs.writeText "password" "hunter2";
150 services.bitcoind.default.enable = true;
151 services.bitcoind.default.rpc.users.bitcoinrpc.passwordHMAC = "e8fe33f797e698ac258c16c8d7aadfbe$872bdb8f4d787367c26bcfd75e6c23c4f19d44a69f5d1ad329e5adf3f82710f7";
154 wait_for_unit("prometheus-bitcoin-exporter.service")
155 wait_for_unit("bitcoind-default.service")
156 wait_for_open_port(9332)
157 succeed("curl -sSf http://localhost:9332/metrics | grep '^bitcoin_blocks '")
164 configFile = pkgs.writeText "config.yml" (builtins.toJSON {
167 icmp.preferred_ip_protocol = "ip6";
172 wait_for_unit("prometheus-blackbox-exporter.service")
173 wait_for_open_port(9115)
175 "curl -sSf 'http://localhost:9115/probe?target=localhost&module=icmp_v6' | grep 'probe_success 1'"
183 extraFlags = [ "--web.collectd-push-path /collectd" ];
185 exporterTest = let postData = replaceChars [ "\n" ] [ "" ] ''
192 "plugin":"testplugin",
197 wait_for_unit("prometheus-collectd-exporter.service")
198 wait_for_open_port(9103)
200 'echo \'${postData}\'> /tmp/data.json'
202 succeed('sed -ie "s DATE $(date +%s) " /tmp/data.json')
204 "curl -sSfH 'Content-Type: application/json' -X POST --data @/tmp/data.json localhost:9103/collectd"
207 "curl -sSf localhost:9103/metrics | grep 'collectd_testplugin_gauge{instance=\"testhost\"} 23'"
215 leasesPath = "/var/lib/dnsmasq/dnsmasq.leases";
218 services.dnsmasq.enable = true;
221 wait_for_unit("prometheus-dnsmasq-exporter.service")
222 wait_for_open_port(9153)
223 succeed("curl -sSf http://localhost:9153/metrics | grep 'dnsmasq_leases 0'")
227 # Access to WHOIS server is required to properly test this exporter, so
228 # just perform basic sanity check that the exporter is running and returns
235 wait_for_unit("prometheus-domain-exporter.service")
236 wait_for_open_port(9222)
238 "curl -sSf 'http://localhost:9222/probe?target=nixos.org' | grep 'domain_probe_success 0'"
246 scopes = [ "global" ];
247 socketPath = "/var/run/dovecot2/old-stats";
248 user = "root"; # <- don't use user root in production
251 services.dovecot2.enable = true;
254 wait_for_unit("prometheus-dovecot-exporter.service")
255 wait_for_open_port(9166)
257 "curl -sSf http://localhost:9166/metrics | grep 'dovecot_up{scope=\"global\"} 1'"
265 tokenPath = pkgs.writeText "token" "abc123";
268 # noop: fastly's exporter can't start without first talking to fastly
269 # see: https://github.com/peterbourgon/fastly-exporter/issues/87
276 # TODO add proper test case
281 wait_for_unit("prometheus-fritzbox-exporter.service")
282 wait_for_open_port(9133)
284 "curl -sSf http://localhost:9133/metrics | grep 'fritzbox_exporter_collect_errors 0'"
295 wait_for_unit("prometheus-influxdb-exporter.service")
296 wait_for_open_port(9122)
298 "curl -XPOST http://localhost:9122/write --data-binary 'influxdb_exporter,distro=nixos,added_in=21.09 value=1'"
301 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
305 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
315 wait_for_unit("prometheus-ipmi-exporter.service")
316 wait_for_open_port(9290)
318 "curl -sSf http://localhost:9290/metrics | grep 'ipmi_scrape_duration_seconds'"
328 systemd.services.prometheus-jitsi-exporter.after = [ "jitsi-videobridge2.service" ];
329 services.jitsi-videobridge = {
331 apis = [ "colibri" "rest" ];
335 wait_for_unit("jitsi-videobridge2.service")
336 wait_for_open_port(8080)
337 wait_for_unit("prometheus-jitsi-exporter.service")
338 wait_for_open_port(9700)
340 'journalctl -eu prometheus-jitsi-exporter.service -o cat | grep "key=participants"'
342 succeed("curl -sSf 'localhost:9700/metrics' | grep 'jitsi_participants 0'")
349 url = "http://localhost";
350 configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON {
352 { name = "json_test_metric"; path = "{ .test }"; }
357 systemd.services.prometheus-json-exporter.after = [ "nginx.service" ];
360 virtualHosts.localhost.locations."/".extraConfig = ''
361 return 200 "{\"test\":1}";
366 wait_for_unit("nginx.service")
367 wait_for_open_port(80)
368 wait_for_unit("prometheus-json-exporter.service")
369 wait_for_open_port(7979)
371 "curl -sSf 'localhost:7979/probe?target=http://localhost' | grep 'json_test_metric 1'"
377 controlSocketPathV4 = "/run/kea/dhcp4.sock";
378 controlSocketPathV6 = "/run/kea/dhcp6.sock";
383 controlSocketPaths = [
394 socket-type = "unix";
395 socket-name = controlSocketPathV4;
403 socket-type = "unix";
404 socket-name = controlSocketPathV6;
412 wait_for_unit("kea-dhcp4-server.service")
413 wait_for_unit("kea-dhcp6-server.service")
414 wait_for_file("${controlSocketPathV4}")
415 wait_for_file("${controlSocketPathV6}")
416 wait_for_unit("prometheus-kea-exporter.service")
417 wait_for_open_port(9547)
419 "curl --fail localhost:9547/metrics | grep 'packets_received_total'"
431 extraArgs = [ "-v" ];
438 global-module: mod-stats
441 journal-db: /var/lib/knot/journal
442 kasp-db: /var/lib/knot/kasp
443 timer-db: /var/lib/knot/timer
444 zonefile-load: difference
445 storage: ${pkgs.buildEnv {
448 (pkgs.writeTextDir "test.zone" ''
449 @ SOA ns.example.com. noc.example.com. 2019031301 86400 7200 3600000 172800
465 module: mod-stats/custom
470 wait_for_unit("knot.service")
471 wait_for_unit("prometheus-knot-exporter.service")
472 wait_for_open_port(9433)
473 succeed("curl -sSf 'localhost:9433' | grep 'knot_server_zone_count 1.0'")
478 # A hardware device is required to properly test this exporter, so just
479 # perform a couple of basic sanity checks that the exporter is running
480 # and requires a target, but cannot reach a specified target.
485 wait_for_unit("prometheus-keylight-exporter.service")
486 wait_for_open_port(9288)
488 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics | grep '400'"
491 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics?target=nosuchdevice | grep '500'"
499 lndTlsPath = "/var/lib/lnd/tls.cert";
500 lndMacaroonDir = "/var/lib/lnd";
501 extraFlags = [ "--lnd.network=regtest" ];
504 systemd.services.prometheus-lnd-exporter.serviceConfig.RestartSec = 15;
505 systemd.services.prometheus-lnd-exporter.after = [ "lnd.service" ];
506 services.bitcoind.regtest = {
509 rpcauth=bitcoinrpc:e8fe33f797e698ac258c16c8d7aadfbe$872bdb8f4d787367c26bcfd75e6c23c4f19d44a69f5d1ad329e5adf3f82710f7
510 zmqpubrawblock=tcp://127.0.0.1:28332
511 zmqpubrawtx=tcp://127.0.0.1:28333
513 extraCmdlineOptions = [ "-regtest" ];
515 systemd.services.lnd = {
516 serviceConfig.ExecStart = ''
517 ${pkgs.lnd}/bin/lnd \
518 --datadir=/var/lib/lnd \
519 --tlscertpath=/var/lib/lnd/tls.cert \
520 --tlskeypath=/var/lib/lnd/tls.key \
521 --logdir=/var/log/lnd \
524 --bitcoin.node=bitcoind \
525 --bitcoind.rpcuser=bitcoinrpc \
526 --bitcoind.rpcpass=hunter2 \
527 --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 \
528 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 \
529 --readonlymacaroonpath=/var/lib/lnd/readonly.macaroon
531 serviceConfig.StateDirectory = "lnd";
532 wantedBy = [ "multi-user.target" ];
533 after = [ "network.target" ];
535 # initialize wallet, creates macaroon needed by exporter
536 systemd.services.lnd.postStart = ''
537 ${pkgs.curl}/bin/curl \
540 --retry-connrefused \
541 --cacert /var/lib/lnd/tls.cert \
543 https://localhost:8080/v1/genseed | ${pkgs.jq}/bin/jq -c '.cipher_seed_mnemonic' > /tmp/seed
544 ${pkgs.curl}/bin/curl \
547 --retry-connrefused \
548 --cacert /var/lib/lnd/tls.cert \
550 -d "{\"wallet_password\": \"asdfasdfasdf\", \"cipher_seed_mnemonic\": $(cat /tmp/seed | tr -d '\n')}" \
551 https://localhost:8080/v1/initwallet
555 wait_for_unit("lnd.service")
556 wait_for_open_port(10009)
557 wait_for_unit("prometheus-lnd-exporter.service")
558 wait_for_open_port(9092)
559 succeed("curl -sSf localhost:9092/metrics | grep '^lnd_peer_count'")
567 monitoringInterval = "2s";
568 mailCheckTimeout = "10s";
571 server = "localhost";
573 from = "mail-exporter@localhost";
574 to = "mail-exporter@localhost";
575 detectionDir = "/var/spool/mail/mail-exporter/new";
580 services.postfix.enable = true;
581 systemd.services.prometheus-mail-exporter = {
582 after = [ "postfix.service" ];
583 requires = [ "postfix.service" ];
586 "${pkgs.writeShellScript "create-maildir" ''
587 mkdir -p -m 0700 mail-exporter/new
592 ReadWritePaths = "/var/spool/mail";
593 WorkingDirectory = "/var/spool/mail";
596 users.users.mailexporter = {
598 group = "mailexporter";
600 users.groups.mailexporter = {};
603 wait_for_unit("postfix.service")
604 wait_for_unit("prometheus-mail-exporter.service")
605 wait_for_open_port(9225)
607 "curl -sSf http://localhost:9225/metrics | grep 'mail_deliver_success{configname=\"testserver\"} 1'"
615 extraFlags = [ "-timeout=1s" ];
620 address = "192.168.42.48";
644 wait_for_unit("prometheus-mikrotik-exporter.service")
645 wait_for_open_port(9436)
647 "curl -sSf http://localhost:9436/metrics | grep 'mikrotik_scrape_collector_success{device=\"router\"} 0'"
658 # ModemManager is installed when NetworkManager is enabled. Ensure it is
659 # started and is wanted by NM and the exporter to start everything up
660 # in the right order.
661 networking.networkmanager.enable = true;
662 systemd.services.ModemManager = {
664 wantedBy = [ "NetworkManager.service" "prometheus-modemmanager-exporter.service" ];
668 wait_for_unit("ModemManager.service")
669 wait_for_unit("prometheus-modemmanager-exporter.service")
670 wait_for_open_port(9539)
672 "curl -sSf http://localhost:9539/metrics | grep 'modemmanager_info'"
680 passwordFile = "/var/nextcloud-pwfile";
681 url = "http://localhost";
684 systemd.services.nc-pwfile =
686 passfile = (pkgs.writeText "pwfile" "snakeoilpw");
689 requiredBy = [ "prometheus-nextcloud-exporter.service" ];
690 before = [ "prometheus-nextcloud-exporter.service" ];
691 serviceConfig.ExecStart = ''
692 ${pkgs.coreutils}/bin/install -o nextcloud-exporter -m 0400 ${passfile} /var/nextcloud-pwfile
697 virtualHosts."localhost" = {
698 basicAuth.nextcloud-exporter = "snakeoilpw";
700 root = "${pkgs.prometheus-nextcloud-exporter.src}/serverinfo/testdata";
701 tryFiles = "/negative-space.json =404";
707 wait_for_unit("nginx.service")
708 wait_for_unit("prometheus-nextcloud-exporter.service")
709 wait_for_open_port(9205)
710 succeed("curl -sSf http://localhost:9205/metrics | grep 'nextcloud_up 1'")
722 virtualHosts."test".extraConfig = "return 204;";
726 wait_for_unit("nginx.service")
727 wait_for_unit("prometheus-nginx-exporter.service")
728 wait_for_open_port(9113)
729 succeed("curl -sSf http://localhost:9113/metrics | grep 'nginx_up 1'")
742 files = [ "/var/log/nginx/filelogger.access.log" ];
749 listen_address = "udp://127.0.0.1:10000";
764 server_name filelogger.local;
765 access_log /var/log/nginx/filelogger.access.log;
769 server_name syslogger.local;
770 access_log syslog:server=127.0.0.1:10000,tag=nginx,severity=info;
776 wait_for_unit("nginx.service")
777 wait_for_unit("prometheus-nginxlog-exporter.service")
778 wait_for_open_port(9117)
779 wait_for_open_port(80)
780 wait_for_open_port(81)
781 succeed("curl http://localhost")
784 "curl -sSf http://localhost:9117/metrics | grep 'filelogger_http_response_count_total' | grep 1"
786 succeed("curl http://localhost:81")
789 "curl -sSf http://localhost:9117/metrics | grep 'syslogger_http_response_count_total' | grep 1"
799 wait_for_unit("prometheus-node-exporter.service")
800 wait_for_open_port(9100)
802 "curl -sSf http://localhost:9100/metrics | grep 'node_exporter_build_info{.\\+} 1'"
810 ldapCredentialFile = "${pkgs.writeText "exporter.yml" ''
811 ldapUser: "cn=root,dc=example"
812 ldapPass: "notapassword"
816 services.openldap = {
818 settings.children = {
819 "cn=schema".includes = [
820 "${pkgs.openldap}/etc/schema/core.ldif"
821 "${pkgs.openldap}/etc/schema/cosine.ldif"
822 "${pkgs.openldap}/etc/schema/inetorgperson.ldif"
823 "${pkgs.openldap}/etc/schema/nis.ldif"
825 "olcDatabase={1}mdb" = {
827 objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
828 olcDatabase = "{1}mdb";
829 olcDbDirectory = "/var/db/openldap";
830 olcSuffix = "dc=example";
833 base64 = "Y249cm9vdCxkYz1leGFtcGxl";
836 path = "${pkgs.writeText "rootpw" "notapassword"}";
840 "olcDatabase={2}monitor".attrs = {
841 objectClass = [ "olcDatabaseConfig" ];
842 olcDatabase = "{2}monitor";
843 olcAccess = [ "to dn.subtree=cn=monitor by users read" ];
846 declarativeContents."dc=example" = ''
851 dn: ou=users,dc=example
852 objectClass: organizationalUnit
858 wait_for_unit("prometheus-openldap-exporter.service")
859 wait_for_open_port(389)
860 wait_for_open_port(9330)
862 "curl -sSf http://localhost:9330/metrics | grep 'openldap_scrape{result=\"ok\"} 1'"
871 statusPaths = [ "/run/openvpn-test" ];
874 users.groups.openvpn = { };
875 services.openvpn.servers.test = {
878 status /run/openvpn-test
881 up = "chmod g+r /run/openvpn-test";
883 systemd.services."openvpn-test".serviceConfig.Group = "openvpn";
886 wait_for_unit("openvpn-test.service")
887 wait_for_unit("prometheus-openvpn-exporter.service")
888 succeed("curl -sSf http://localhost:9176/metrics | grep 'openvpn_up{.*} 1'")
897 services.postfix.enable = true;
900 wait_for_unit("prometheus-postfix-exporter.service")
901 wait_for_file("/var/lib/postfix/queue/public/showq")
902 wait_for_open_port(9154)
904 "curl -sSf http://localhost:9154/metrics | grep 'postfix_up{path=\"/var/lib/postfix/queue/public/showq\"} 1'"
907 "curl -sSf http://localhost:9154/metrics | grep 'postfix_smtpd_connects_total 0'"
909 succeed("curl -sSf http://localhost:9154/metrics | grep 'postfix_up{.*} 1'")
916 runAsLocalSuperUser = true;
919 services.postgresql.enable = true;
922 wait_for_unit("prometheus-postgres-exporter.service")
923 wait_for_open_port(9187)
924 wait_for_unit("postgresql.service")
926 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
928 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
929 systemctl("stop postgresql.service")
931 "curl -sSf http://localhost:9187/metrics | grep -v 'pg_exporter_last_scrape_error 0'"
933 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 0'")
934 systemctl("start postgresql.service")
935 wait_for_unit("postgresql.service")
937 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
939 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
946 settings.process_names = [
947 # Remove nix store path from process name
948 { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
952 wait_for_unit("prometheus-process-exporter.service")
953 wait_for_open_port(9256)
955 "curl -sSf localhost:9256/metrics | grep -q '{}'".format(
956 'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter '
963 pveExporterEnvFile = pkgs.writeTextFile {
966 PVE_USER="test_user@pam"
967 PVE_PASSWORD="hunter3"
968 PVE_VERIFY_SSL="false"
974 environmentFile = pveExporterEnvFile;
977 wait_for_unit("prometheus-pve-exporter.service")
978 wait_for_open_port(9221)
979 wait_until_succeeds("curl localhost:9221")
984 nodeName = "py_air_control";
987 deviceHostname = "127.0.0.1";
990 wait_for_unit("prometheus-py-air-control-exporter.service")
991 wait_for_open_port(9896)
993 "curl -sSf http://localhost:9896/metrics | grep 'py_air_control_sampling_error_total'"
1002 metricProvider.services.redis.servers."".enable = true;
1004 wait_for_unit("redis.service")
1005 wait_for_unit("prometheus-redis-exporter.service")
1006 wait_for_open_port(6379)
1007 wait_for_open_port(9121)
1008 wait_until_succeeds("curl -sSf localhost:9121/metrics | grep 'redis_up 1'")
1017 services.rspamd.enable = true;
1020 wait_for_unit("rspamd.service")
1021 wait_for_unit("prometheus-rspamd-exporter.service")
1022 wait_for_open_port(11334)
1023 wait_for_open_port(7980)
1024 wait_until_succeeds(
1025 "curl -sSf 'localhost:7980/probe?target=http://localhost:11334/stat' | grep 'rspamd_scanned{host=\"rspamd\"} 0'"
1035 # Mock rtl_433 binary to return a dummy metric stream.
1036 nixpkgs.overlays = [
1038 rtl_433 = self.runCommand "rtl_433" { } ''
1040 cat <<EOF > "$out/bin/rtl_433"
1043 printf '{"time" : "2020-04-26 13:37:42", "model" : "zopieux", "id" : 55, "channel" : 3, "temperature_C" : 18.000}\n'
1047 chmod +x "$out/bin/rtl_433"
1053 wait_for_unit("prometheus-rtl_433-exporter.service")
1054 wait_for_open_port(9550)
1055 wait_until_succeeds(
1056 "curl -sSf localhost:9550/metrics | grep '{}'".format(
1057 'rtl_433_temperature_celsius{channel="3",id="55",location="",model="zopieux"} 18'
1066 settings.scripts = [
1067 { name = "success"; script = "sleep 1"; }
1071 wait_for_unit("prometheus-script-exporter.service")
1072 wait_for_open_port(9172)
1073 wait_until_succeeds(
1074 "curl -sSf 'localhost:9172/probe?name=success' | grep -q '{}'".format(
1075 'script_success{script="success"} 1'
1089 wait_for_unit("prometheus-smartctl-exporter.service")
1090 wait_for_open_port(9633)
1091 wait_until_succeeds(
1092 "curl -sSf 'localhost:9633/metrics'"
1094 wait_until_succeeds(
1095 'journalctl -eu prometheus-smartctl-exporter.service -o cat | grep "/dev/vda: Unable to detect device type"'
1103 hosts = [ "127.0.0.1" ];
1106 wait_for_unit("prometheus-smokeping-exporter.service")
1107 wait_for_open_port(9374)
1108 wait_until_succeeds(
1109 "curl -sSf localhost:9374/metrics | grep '{}' | grep -v ' 0$'".format(
1110 'smokeping_requests_total{host="127.0.0.1",ip="127.0.0.1"} '
1113 wait_until_succeeds(
1114 "curl -sSf localhost:9374/metrics | grep '{}'".format(
1115 'smokeping_response_ttl{host="127.0.0.1",ip="127.0.0.1"}'
1124 configuration.default = {
1126 auth.community = "public";
1130 wait_for_unit("prometheus-snmp-exporter.service")
1131 wait_for_open_port(9116)
1132 succeed("curl -sSf localhost:9116/metrics | grep 'snmp_request_errors_total 0'")
1138 configuration.jobs.points = {
1141 "postgres://prometheus-sql-exporter@/data?host=/run/postgresql&sslmode=disable"
1145 labels = [ "name" ];
1146 help = "Amount of points accumulated per person";
1147 values = [ "amount" ];
1148 query = "SELECT SUM(amount) as amount, name FROM points GROUP BY name";
1153 user = "prometheus-sql-exporter";
1156 services.postgresql = {
1158 initialScript = builtins.toFile "init.sql" ''
1159 CREATE DATABASE data;
1161 CREATE TABLE points (amount INT, name TEXT);
1162 INSERT INTO points(amount, name) VALUES (1, 'jack');
1163 INSERT INTO points(amount, name) VALUES (2, 'jill');
1164 INSERT INTO points(amount, name) VALUES (3, 'jack');
1166 CREATE USER "prometheus-sql-exporter";
1167 GRANT ALL PRIVILEGES ON DATABASE data TO "prometheus-sql-exporter";
1168 GRANT SELECT ON points TO "prometheus-sql-exporter";
1171 systemd.services.prometheus-sql-exporter.after = [ "postgresql.service" ];
1174 wait_for_unit("prometheus-sql-exporter.service")
1175 wait_for_open_port(9237)
1176 succeed("curl http://localhost:9237/metrics | grep -c 'sql_points{' | grep 2")
1183 modemAddress = "localhost";
1186 systemd.services.prometheus-surfboard-exporter.after = [ "nginx.service" ];
1189 virtualHosts.localhost.locations."/cgi-bin/status".extraConfig = ''
1195 wait_for_unit("nginx.service")
1196 wait_for_open_port(80)
1197 wait_for_unit("prometheus-surfboard-exporter.service")
1198 wait_for_open_port(9239)
1199 succeed("curl -sSf localhost:9239/metrics | grep 'surfboard_up 1'")
1208 "--systemd.collector.enable-restart-count"
1211 metricProvider = { };
1213 wait_for_unit("prometheus-systemd-exporter.service")
1214 wait_for_open_port(9558)
1215 wait_until_succeeds(
1216 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1217 'systemd_unit_state{name="basic.target",state="active",type="target"} 1'
1221 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1222 'systemd_service_restart_total{name="prometheus-systemd-exporter.service"} 0'
1233 # Note: this does not connect the test environment to the Tor network.
1234 # Client, relay, bridge or exit connectivity are disabled by default.
1235 services.tor.enable = true;
1236 services.tor.settings.ControlPort = 9051;
1239 wait_for_unit("tor.service")
1240 wait_for_open_port(9051)
1241 wait_for_unit("prometheus-tor-exporter.service")
1242 wait_for_open_port(9130)
1243 succeed("curl -sSf localhost:9130/metrics | grep 'tor_version{.\\+} 1'")
1248 nodeName = "unifi_poller";
1249 exporterConfig.enable = true;
1250 exporterConfig.controllers = [{ }];
1252 wait_for_unit("prometheus-unifi-poller-exporter.service")
1253 wait_for_open_port(9130)
1255 "curl -sSf localhost:9130/metrics | grep 'unifipoller_build_info{.\\+} 1'"
1264 controlInterface = "/run/unbound/unbound.ctl";
1267 services.unbound = {
1269 localControlSocketPath = "/run/unbound/unbound.ctl";
1271 systemd.services.prometheus-unbound-exporter.serviceConfig = {
1272 SupplementaryGroups = [ "unbound" ];
1276 wait_for_unit("unbound.service")
1277 wait_for_unit("prometheus-unbound-exporter.service")
1278 wait_for_open_port(9167)
1279 succeed("curl -sSf localhost:9167/metrics | grep 'unbound_up 1'")
1289 systemd.services.prometheus-nginx-exporter.after = [ "v2ray.service" ];
1296 services = [ "StatsService" ];
1301 listen = "127.0.0.1";
1305 listen = "127.0.0.1";
1307 protocol = "dokodemo-door";
1308 settings = { address = "127.0.0.1"; };
1314 protocol = "freedom";
1317 protocol = "freedom";
1327 inboundTag = [ "api" ];
1328 outboundTag = "api";
1338 wait_for_unit("prometheus-v2ray-exporter.service")
1339 wait_for_open_port(9299)
1340 succeed("curl -sSf localhost:9299/scrape | grep 'v2ray_up 1'")
1347 instance = "/var/spool/varnish/varnish";
1351 systemd.services.prometheus-varnish-exporter.after = [
1354 services.varnish = {
1359 .host = "127.0.0.1";
1366 wait_for_unit("prometheus-varnish-exporter.service")
1367 wait_for_open_port(6081)
1368 wait_for_open_port(9131)
1369 succeed("curl -sSf http://localhost:9131/metrics | grep 'varnish_up 1'")
1373 wireguard = let snakeoil = import ./wireguard/snakeoil-keys.nix; in
1375 exporterConfig.enable = true;
1377 networking.wireguard.interfaces.wg0 = {
1378 ips = [ "10.23.42.1/32" "fc00::1/128" ];
1381 inherit (snakeoil.peer0) privateKey;
1384 allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ];
1386 inherit (snakeoil.peer1) publicKey;
1389 systemd.services.prometheus-wireguard-exporter.after = [ "wireguard-wg0.service" ];
1392 wait_for_unit("prometheus-wireguard-exporter.service")
1393 wait_for_open_port(9586)
1394 wait_until_succeeds(
1395 "curl -sSf http://localhost:9586/metrics | grep '${snakeoil.peer1.publicKey}'"
1402 (exporter: testConfig: (makeTest (
1404 nodeName = testConfig.nodeName or exporter;
1408 name = "prometheus-${exporter}-exporter";
1410 nodes.${nodeName} = mkMerge [{
1411 services.prometheus.exporters.${exporter} = testConfig.exporterConfig;
1412 } testConfig.metricProvider or { }];
1416 ${concatStringsSep "\n" (map (line:
1417 if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")")
1419 else "${nodeName}.${line}"
1420 ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
1421 ${nodeName}.shutdown()
1424 meta = with maintainers; {
1425 maintainers = [ willibutz ];