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 replaceStrings singleton splitString makeBinPath;
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'"
186 services.borgmatic.enable = true;
187 services.borgmatic.settings.source_directories = [ "/home" ];
188 services.borgmatic.settings.repositories = [ { label = "local"; path = "/var/backup"; } ];
189 services.borgmatic.settings.keep_daily = 10;
192 succeed("borgmatic rcreate -e none")
194 wait_for_unit("prometheus-borgmatic-exporter.service")
195 wait_for_open_port(9996)
196 succeed("curl -sSf localhost:9996/metrics | grep 'borg_total_backups{repository=\"/var/backup\"} 1'")
203 extraFlags = [ "--web.collectd-push-path /collectd" ];
205 exporterTest = let postData = replaceStrings [ "\n" ] [ "" ] ''
212 "plugin":"testplugin",
217 wait_for_unit("prometheus-collectd-exporter.service")
218 wait_for_open_port(9103)
220 'echo \'${postData}\'> /tmp/data.json'
222 succeed('sed -ie "s DATE $(date +%s) " /tmp/data.json')
224 "curl -sSfH 'Content-Type: application/json' -X POST --data @/tmp/data.json localhost:9103/collectd"
227 "curl -sSf localhost:9103/metrics | grep 'collectd_testplugin_gauge{instance=\"testhost\"} 23'"
236 listenAddress = "127.0.0.1";
240 delugePasswordFile = pkgs.writeText "password" "weak_password";
243 services.deluge.enable = true;
244 services.deluge.declarative = true;
245 services.deluge.config.daemon_port = 2345;
246 services.deluge.authFile = pkgs.writeText "authFile" ''
247 localclient:abcdef:10
248 user:weak_password:10
252 wait_for_unit("deluged.service")
253 wait_for_open_port(2345)
254 wait_for_unit("prometheus-deluge-exporter.service")
255 wait_for_open_port(1234)
256 succeed("curl -sSf http://localhost:1234 | grep 'deluge_torrents'")
263 leasesPath = "/var/lib/dnsmasq/dnsmasq.leases";
266 services.dnsmasq.enable = true;
269 wait_for_unit("dnsmasq.service")
270 wait_for_open_port(53)
271 wait_for_file("/var/lib/dnsmasq/dnsmasq.leases")
272 wait_for_unit("prometheus-dnsmasq-exporter.service")
273 wait_for_open_port(9153)
274 succeed("curl -sSf http://localhost:9153/metrics | grep 'dnsmasq_leases 0'")
284 zone = "example.com";
290 resolvers = [ "127.0.0.1:53" ];
295 settingsFile = pkgs.writeText "knot.conf" ''
300 storage: ${pkgs.buildEnv {
302 paths = [(pkgs.writeTextDir "example.com.zone" ''
303 @ SOA ns1.example.com. noc.example.com. 2024032401 86400 7200 3600000 172800
308 zonefile-load: difference
311 - domain: example.com
312 file: example.com.zone
318 wait_for_unit("knot.service")
319 wait_for_open_port(53)
320 wait_for_unit("prometheus-dnssec-exporter.service")
321 wait_for_open_port(9204)
322 succeed("curl -sSf http://localhost:9204/metrics | grep 'example.com'")
326 # Access to WHOIS server is required to properly test this exporter, so
327 # just perform basic sanity check that the exporter is running and returns
334 wait_for_unit("prometheus-domain-exporter.service")
335 wait_for_open_port(9222)
336 succeed("curl -sSf 'http://localhost:9222/probe?target=nixos.org'")
343 scopes = [ "global" ];
344 socketPath = "/var/run/dovecot2/old-stats";
345 user = "root"; # <- don't use user root in production
348 services.dovecot2.enable = true;
351 wait_for_unit("prometheus-dovecot-exporter.service")
352 wait_for_open_port(9166)
354 "curl -sSf http://localhost:9166/metrics | grep 'dovecot_up{scope=\"global\"} 1'"
362 tokenPath = pkgs.writeText "token" "abc123";
366 wait_for_unit("prometheus-fastly-exporter.service")
367 wait_for_open_port(9118)
372 # TODO add proper test case
377 wait_for_unit("prometheus-fritzbox-exporter.service")
378 wait_for_open_port(9133)
380 "curl -sSf http://localhost:9133/metrics | grep 'fritzbox_exporter_collect_errors 0'"
390 mappingSettings.mappings = [{
400 wait_for_unit("prometheus-graphite-exporter.service")
401 wait_for_open_port(9108)
402 wait_for_open_port(9109)
403 succeed("echo test.tcp.foo-bar 1234 $(date +%s) | nc -w1 localhost 9109")
404 succeed("curl -sSf http://localhost:9108/metrics | grep 'testing{author=\"foo-bar\",protocol=\"tcp\"} 1234'")
414 default = { username = "username"; password = "password"; };
419 wait_for_unit("prometheus-idrac-exporter.service")
420 wait_for_open_port(9348)
421 wait_until_succeeds("curl localhost:9348")
431 wait_for_unit("prometheus-influxdb-exporter.service")
432 wait_for_open_port(9122)
434 "curl -XPOST http://localhost:9122/write --data-binary 'influxdb_exporter,distro=nixos,added_in=21.09 value=1'"
437 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
441 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
451 wait_for_unit("prometheus-ipmi-exporter.service")
452 wait_for_open_port(9290)
454 "curl -sSf http://localhost:9290/metrics | grep 'ipmi_scrape_duration_seconds'"
464 systemd.services.prometheus-jitsi-exporter.after = [ "jitsi-videobridge2.service" ];
465 services.jitsi-videobridge = {
467 colibriRestApi = true;
471 wait_for_unit("jitsi-videobridge2.service")
472 wait_for_open_port(8080)
473 wait_for_unit("prometheus-jitsi-exporter.service")
474 wait_for_open_port(9700)
476 'journalctl -eu prometheus-jitsi-exporter.service -o cat | grep "key=participants"'
478 succeed("curl -sSf 'localhost:9700/metrics' | grep 'jitsi_participants 0'")
485 configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON {
489 { name = "json_test_metric"; path = "{ .test }"; }
496 systemd.services.prometheus-json-exporter.after = [ "nginx.service" ];
499 virtualHosts.localhost.locations."/".extraConfig = ''
500 return 200 "{\"test\":1}";
505 wait_for_unit("nginx.service")
506 wait_for_open_port(80)
507 wait_for_unit("prometheus-json-exporter.service")
508 wait_for_open_port(7979)
510 "curl -sSf 'localhost:7979/probe?target=http://localhost' | grep 'json_test_metric 1'"
522 extraArgs = [ "-v" ];
523 settingsFile = pkgs.writeText "knot.conf" ''
529 global-module: mod-stats
532 zonefile-load: difference
533 storage: ${pkgs.buildEnv {
536 (pkgs.writeTextDir "test.zone" ''
537 @ SOA ns.example.com. noc.example.com. 2019031301 86400 7200 3600000 172800
553 module: mod-stats/custom
558 wait_for_unit("knot.service")
559 wait_for_unit("prometheus-knot-exporter.service")
560 wait_for_open_port(9433)
561 succeed("curl -sSf 'localhost:9433' | grep '2\.019031301'")
566 # A hardware device is required to properly test this exporter, so just
567 # perform a couple of basic sanity checks that the exporter is running
568 # and requires a target, but cannot reach a specified target.
573 wait_for_unit("prometheus-keylight-exporter.service")
574 wait_for_open_port(9288)
576 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics | grep '400'"
579 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics?target=nosuchdevice | grep '500'"
587 lndTlsPath = "/var/lib/lnd/tls.cert";
588 lndMacaroonDir = "/var/lib/lnd";
589 extraFlags = [ "--lnd.network=regtest" ];
592 systemd.services.prometheus-lnd-exporter.serviceConfig.RestartSec = 15;
593 systemd.services.prometheus-lnd-exporter.after = [ "lnd.service" ];
594 services.bitcoind.regtest = {
597 rpcauth=bitcoinrpc:e8fe33f797e698ac258c16c8d7aadfbe$872bdb8f4d787367c26bcfd75e6c23c4f19d44a69f5d1ad329e5adf3f82710f7
598 zmqpubrawblock=tcp://127.0.0.1:28332
599 zmqpubrawtx=tcp://127.0.0.1:28333
601 extraCmdlineOptions = [ "-regtest" ];
603 systemd.services.lnd = {
604 serviceConfig.ExecStart = ''
605 ${pkgs.lnd}/bin/lnd \
606 --datadir=/var/lib/lnd \
607 --tlscertpath=/var/lib/lnd/tls.cert \
608 --tlskeypath=/var/lib/lnd/tls.key \
609 --logdir=/var/log/lnd \
612 --bitcoin.node=bitcoind \
613 --bitcoind.rpcuser=bitcoinrpc \
614 --bitcoind.rpcpass=hunter2 \
615 --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 \
616 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 \
617 --readonlymacaroonpath=/var/lib/lnd/readonly.macaroon
619 serviceConfig.StateDirectory = "lnd";
620 wantedBy = [ "multi-user.target" ];
621 after = [ "network.target" ];
623 # initialize wallet, creates macaroon needed by exporter
624 systemd.services.lnd.postStart = ''
625 ${pkgs.curl}/bin/curl \
628 --retry-connrefused \
629 --cacert /var/lib/lnd/tls.cert \
631 https://localhost:8080/v1/genseed | ${pkgs.jq}/bin/jq -c '.cipher_seed_mnemonic' > /tmp/seed
632 ${pkgs.curl}/bin/curl \
635 --retry-connrefused \
636 --cacert /var/lib/lnd/tls.cert \
638 -d "{\"wallet_password\": \"asdfasdfasdf\", \"cipher_seed_mnemonic\": $(cat /tmp/seed | tr -d '\n')}" \
639 https://localhost:8080/v1/initwallet
643 wait_for_unit("lnd.service")
644 wait_for_open_port(10009)
645 wait_for_unit("prometheus-lnd-exporter.service")
646 wait_for_open_port(9092)
647 succeed("curl -sSf localhost:9092/metrics | grep '^lnd_peer_count'")
655 monitoringInterval = "2s";
656 mailCheckTimeout = "10s";
659 server = "localhost";
661 from = "mail-exporter@localhost";
662 to = "mail-exporter@localhost";
663 detectionDir = "/var/spool/mail/mail-exporter/new";
668 services.postfix.enable = true;
669 systemd.services.prometheus-mail-exporter = {
670 after = [ "postfix.service" ];
671 requires = [ "postfix.service" ];
674 "${pkgs.writeShellScript "create-maildir" ''
675 mkdir -p -m 0700 mail-exporter/new
680 ReadWritePaths = "/var/spool/mail";
681 WorkingDirectory = "/var/spool/mail";
684 users.users.mailexporter = {
686 group = "mailexporter";
688 users.groups.mailexporter = {};
691 wait_for_unit("postfix.service")
692 wait_for_unit("prometheus-mail-exporter.service")
693 wait_for_open_port(9225)
695 "curl -sSf http://localhost:9225/metrics | grep 'mail_deliver_success{configname=\"testserver\"} 1'"
703 extraFlags = [ "-timeout=1s" ];
708 address = "192.168.42.48";
732 wait_for_unit("prometheus-mikrotik-exporter.service")
733 wait_for_open_port(9436)
735 "curl -sSf http://localhost:9436/metrics | grep 'mikrotik_scrape_collector_success{device=\"router\"} 0'"
746 # ModemManager is installed when NetworkManager is enabled. Ensure it is
747 # started and is wanted by NM and the exporter to start everything up
748 # in the right order.
749 networking.networkmanager.enable = true;
750 systemd.services.ModemManager = {
752 wantedBy = [ "NetworkManager.service" "prometheus-modemmanager-exporter.service" ];
756 wait_for_unit("ModemManager.service")
757 wait_for_unit("prometheus-modemmanager-exporter.service")
758 wait_for_open_port(9539)
760 "curl -sSf http://localhost:9539/metrics | grep 'modemmanager_info'"
768 runAsLocalSuperUser = true;
769 configFile = pkgs.writeText "test-prometheus-exporter-mysqld-config.my-cnf" ''
772 password = snakeoilpassword
778 package = pkgs.mariadb;
779 initialScript = pkgs.writeText "mysql-init-script.sql" ''
780 CREATE USER 'exporter'@'localhost'
781 IDENTIFIED BY 'snakeoilpassword'
782 WITH MAX_USER_CONNECTIONS 3;
783 GRANT PROCESS, REPLICATION CLIENT, SLAVE MONITOR, SELECT ON *.* TO 'exporter'@'localhost';
788 wait_for_unit("prometheus-mysqld-exporter.service")
789 wait_for_open_port(9104)
790 wait_for_unit("mysql.service")
791 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 1'")
792 systemctl("stop mysql.service")
793 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 0'")
794 systemctl("start mysql.service")
795 wait_for_unit("mysql.service")
796 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 1'")
803 passwordFile = "/var/nextcloud-pwfile";
804 url = "http://localhost";
807 systemd.services.nc-pwfile =
809 passfile = (pkgs.writeText "pwfile" "snakeoilpw");
812 requiredBy = [ "prometheus-nextcloud-exporter.service" ];
813 before = [ "prometheus-nextcloud-exporter.service" ];
814 serviceConfig.ExecStart = ''
815 ${pkgs.coreutils}/bin/install -o nextcloud-exporter -m 0400 ${passfile} /var/nextcloud-pwfile
820 virtualHosts."localhost" = {
821 basicAuth.nextcloud-exporter = "snakeoilpw";
823 root = "${pkgs.prometheus-nextcloud-exporter.src}/serverinfo/testdata";
824 tryFiles = "/negative-space.json =404";
830 wait_for_unit("nginx.service")
831 wait_for_unit("prometheus-nextcloud-exporter.service")
832 wait_for_open_port(9205)
833 succeed("curl -sSf http://localhost:9205/metrics | grep 'nextcloud_up 1'")
840 constLabels = [ "foo=bar" ];
846 virtualHosts."test".extraConfig = "return 204;";
850 wait_for_unit("nginx.service")
851 wait_for_unit("prometheus-nginx-exporter.service")
852 wait_for_open_port(9113)
853 succeed("curl -sSf http://localhost:9113/metrics | grep 'nginx_up{foo=\"bar\"} 1'")
866 files = [ "/var/log/nginx/filelogger.access.log" ];
873 listen_address = "udp://127.0.0.1:10000";
888 server_name filelogger.local;
889 access_log /var/log/nginx/filelogger.access.log;
893 server_name syslogger.local;
894 access_log syslog:server=127.0.0.1:10000,tag=nginx,severity=info;
900 wait_for_unit("nginx.service")
901 wait_for_unit("prometheus-nginxlog-exporter.service")
902 wait_for_open_port(9117)
903 wait_for_open_port(80)
904 wait_for_open_port(81)
905 succeed("curl http://localhost")
908 "curl -sSf http://localhost:9117/metrics | grep 'filelogger_http_response_count_total' | grep 1"
910 succeed("curl http://localhost:81")
913 "curl -sSf http://localhost:9117/metrics | grep 'syslogger_http_response_count_total' | grep 1"
923 wait_for_unit("prometheus-node-exporter.service")
924 wait_for_open_port(9100)
926 "curl -sSf http://localhost:9100/metrics | grep 'node_exporter_build_info{.\\+} 1'"
934 connectionEnvFile = "${pkgs.writeText "connstr-env" ''
935 PGBOUNCER_EXPORTER_CONNECTION_STRING=postgres://admin@localhost:6432/pgbouncer?sslmode=disable
940 services.postgresql.enable = true;
941 services.pgbouncer = {
947 max_client_conn = 99;
948 # https://github.com/prometheus-community/pgbouncer_exporter#pgbouncer-configuration
949 ignore_startup_parameters = "extra_float_digits";
952 postgres = concatStringsSep " " [
953 "host=/run/postgresql"
963 wait_for_unit("postgresql.service")
964 wait_for_unit("pgbouncer.service")
965 wait_for_unit("prometheus-pgbouncer-exporter.service")
966 wait_for_open_port(9127)
967 succeed("curl -sSf http://localhost:9127/metrics | grep 'pgbouncer_up 1'")
969 "curl -sSf http://localhost:9127/metrics | grep 'pgbouncer_config_max_client_connections 99'"
975 nodeName = "php_fpm";
978 environmentFile = pkgs.writeTextFile {
979 name = "/tmp/prometheus-php-fpm-exporter.env";
981 PHP_FPM_SCRAPE_URI="tcp://127.0.0.1:9000/status"
986 users.users."php-fpm-exporter" = {
988 group = "php-fpm-exporter";
990 users.groups."php-fpm-exporter" = {};
991 services.phpfpm.pools."php-fpm-exporter" = {
992 user = "php-fpm-exporter";
993 group = "php-fpm-exporter";
996 "pm.max_children" = 32;
997 "pm.max_requests" = 500;
998 "pm.start_servers" = 2;
999 "pm.min_spare_servers" = 2;
1000 "pm.max_spare_servers" = 5;
1001 "pm.status_path" = "/status";
1002 "listen" = "127.0.0.1:9000";
1003 "listen.allowed_clients" = "127.0.0.1";
1005 phpEnv."PATH" = makeBinPath [ pkgs.php ];
1009 wait_for_unit("phpfpm-php-fpm-exporter.service")
1010 wait_for_unit("prometheus-php-fpm-exporter.service")
1011 succeed("curl -sSf http://localhost:9253/metrics | grep 'phpfpm_up{.*} 1'")
1022 alias = "local machine";
1028 alias = "local machine";
1033 alias = "local machine";
1053 wait_for_unit("prometheus-ping-exporter.service")
1054 wait_for_open_port(9427)
1055 succeed("curl -sSf http://localhost:9427/metrics | grep 'ping_up{.*} 1'")
1064 services.postfix.enable = true;
1067 wait_for_unit("prometheus-postfix-exporter.service")
1068 wait_for_file("/var/lib/postfix/queue/public/showq")
1069 wait_for_open_port(9154)
1070 wait_until_succeeds(
1071 "curl -sSf http://localhost:9154/metrics | grep 'postfix_up{path=\"/var/lib/postfix/queue/public/showq\"} 1'"
1074 "curl -sSf http://localhost:9154/metrics | grep 'postfix_smtpd_connects_total 0'"
1076 succeed("curl -sSf http://localhost:9154/metrics | grep 'postfix_up{.*} 1'")
1083 runAsLocalSuperUser = true;
1086 services.postgresql.enable = true;
1089 wait_for_unit("prometheus-postgres-exporter.service")
1090 wait_for_open_port(9187)
1091 wait_for_unit("postgresql.service")
1093 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
1095 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
1096 systemctl("stop postgresql.service")
1098 "curl -sSf http://localhost:9187/metrics | grep -v 'pg_exporter_last_scrape_error 0'"
1100 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 0'")
1101 systemctl("start postgresql.service")
1102 wait_for_unit("postgresql.service")
1104 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
1106 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
1113 settings.process_names = [
1114 # Remove nix store path from process name
1115 { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
1119 wait_for_unit("prometheus-process-exporter.service")
1120 wait_for_open_port(9256)
1121 wait_until_succeeds(
1122 "curl -sSf localhost:9256/metrics | grep -q '{}'".format(
1123 'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter '
1130 pveExporterEnvFile = pkgs.writeTextFile {
1133 PVE_USER="test_user@pam"
1134 PVE_PASSWORD="hunter3"
1135 PVE_VERIFY_SSL="false"
1141 environmentFile = pveExporterEnvFile;
1144 wait_for_unit("prometheus-pve-exporter.service")
1145 wait_for_open_port(9221)
1146 wait_until_succeeds("curl localhost:9221")
1151 nodeName = "py_air_control";
1154 deviceHostname = "127.0.0.1";
1157 wait_for_unit("prometheus-py-air-control-exporter.service")
1158 wait_for_open_port(9896)
1160 "curl -sSf http://localhost:9896/metrics | grep 'py_air_control_sampling_error_total'"
1169 metricProvider.services.redis.servers."".enable = true;
1171 wait_for_unit("redis.service")
1172 wait_for_unit("prometheus-redis-exporter.service")
1173 wait_for_open_port(6379)
1174 wait_for_open_port(9121)
1175 wait_until_succeeds("curl -sSf localhost:9121/metrics | grep 'redis_up 1'")
1181 repository = "rest:http://127.0.0.1:8000";
1182 passwordFile = pkgs.writeText "restic-test-password" "test-password";
1187 inherit repository passwordFile;
1190 services.restic.server = {
1192 extraFlags = [ "--no-auth" ];
1194 environment.systemPackages = [ pkgs.restic ];
1197 # prometheus-restic-exporter.service fails without initialised repository
1198 systemctl("stop prometheus-restic-exporter.service")
1200 # Initialise the repository
1201 wait_for_unit("restic-rest-server.service")
1202 wait_for_open_port(8000)
1203 succeed("restic init --repo ${repository} --password-file ${passwordFile}")
1205 systemctl("start prometheus-restic-exporter.service")
1206 wait_for_unit("prometheus-restic-exporter.service")
1207 wait_for_open_port(9753)
1208 wait_until_succeeds("curl -sSf localhost:9753/metrics | grep 'restic_check_success 1.0'")
1217 services.rspamd.enable = true;
1220 wait_for_unit("rspamd.service")
1221 wait_for_unit("prometheus-rspamd-exporter.service")
1222 wait_for_open_port(11334)
1223 wait_for_open_port(7980)
1224 wait_until_succeeds(
1225 "curl -sSf 'localhost:7980/probe?target=http://localhost:11334/stat' | grep 'rspamd_scanned{host=\"rspamd\"} 0'"
1235 # Mock rtl_433 binary to return a dummy metric stream.
1236 nixpkgs.overlays = [
1238 rtl_433 = self.runCommand "rtl_433" { } ''
1240 cat <<EOF > "$out/bin/rtl_433"
1243 printf '{"time" : "2020-04-26 13:37:42", "model" : "zopieux", "id" : 55, "channel" : 3, "temperature_C" : 18.000}\n'
1247 chmod +x "$out/bin/rtl_433"
1253 wait_for_unit("prometheus-rtl_433-exporter.service")
1254 wait_for_open_port(9550)
1255 wait_until_succeeds(
1256 "curl -sSf localhost:9550/metrics | grep '{}'".format(
1257 'rtl_433_temperature_celsius{channel="3",id="55",location="",model="zopieux"} 18'
1267 baseUrl = "http://localhost:8080";
1268 apiKeyFile = "/var/sabnzbd-apikey";
1273 services.sabnzbd.enable = true;
1275 # unrar is required for sabnzbd
1276 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "unrar" ];
1278 # extract the generated api key before starting
1279 systemd.services.sabnzbd-apikey = {
1280 requires = [ "sabnzbd.service" ];
1281 after = [ "sabnzbd.service" ];
1282 requiredBy = [ "prometheus-sabnzbd-exporter.service" ];
1283 before = [ "prometheus-sabnzbd-exporter.service" ];
1285 grep -Po '^api_key = \K.+' /var/lib/sabnzbd/sabnzbd.ini > /var/sabnzbd-apikey
1291 wait_for_unit("sabnzbd.service")
1292 wait_for_unit("prometheus-sabnzbd-exporter.service")
1293 wait_for_open_port(8080)
1294 wait_for_open_port(9387)
1295 wait_until_succeeds(
1296 "curl -sSf 'localhost:9387/metrics' | grep 'sabnzbd_queue_size{sabnzbd_instance=\"http://localhost:8080\"} 0.0'"
1306 boot.kernelModules = [ "intel_rapl_common" ];
1309 wait_for_unit("prometheus-scaphandre-exporter.service")
1310 wait_for_open_port(8080)
1311 wait_until_succeeds(
1312 "curl -sSf 'localhost:8080/metrics'"
1320 metrics-file = "${pkgs.writeText "test.json" ''{}''}";
1323 wait_for_unit("prometheus-shelly-exporter.service")
1324 wait_for_open_port(9784)
1325 wait_until_succeeds(
1326 "curl -sSf 'localhost:9784/metrics'"
1334 settings.scripts = [
1335 { name = "success"; script = "sleep 1"; }
1339 wait_for_unit("prometheus-script-exporter.service")
1340 wait_for_open_port(9172)
1341 wait_until_succeeds(
1342 "curl -sSf 'localhost:9172/probe?name=success' | grep -q '{}'".format(
1343 'script_success{script="success"} 1'
1357 wait_until_succeeds(
1358 'journalctl -eu prometheus-smartctl-exporter.service -o cat | grep "Unable to detect device type"'
1366 hosts = [ "127.0.0.1" ];
1369 wait_for_unit("prometheus-smokeping-exporter.service")
1370 wait_for_open_port(9374)
1371 wait_until_succeeds(
1372 "curl -sSf localhost:9374/metrics | grep '{}' | grep -v ' 0$'".format(
1373 'smokeping_requests_total{host="127.0.0.1",ip="127.0.0.1",source=""} '
1376 wait_until_succeeds(
1377 "curl -sSf localhost:9374/metrics | grep '{}'".format(
1378 'smokeping_response_ttl{host="127.0.0.1",ip="127.0.0.1",source=""}'
1389 community = "public";
1395 wait_for_unit("prometheus-snmp-exporter.service")
1396 wait_for_open_port(9116)
1397 succeed("curl -sSf localhost:9116/metrics | grep 'snmp_request_errors_total 0'")
1403 configuration.jobs.points = {
1406 "postgres://prometheus-sql-exporter@/data?host=/run/postgresql&sslmode=disable"
1410 labels = [ "name" ];
1411 help = "Amount of points accumulated per person";
1412 values = [ "amount" ];
1413 query = "SELECT SUM(amount) as amount, name FROM points GROUP BY name";
1418 user = "prometheus-sql-exporter";
1421 services.postgresql = {
1423 initialScript = builtins.toFile "init.sql" ''
1424 CREATE DATABASE data;
1426 CREATE TABLE points (amount INT, name TEXT);
1427 INSERT INTO points(amount, name) VALUES (1, 'jack');
1428 INSERT INTO points(amount, name) VALUES (2, 'jill');
1429 INSERT INTO points(amount, name) VALUES (3, 'jack');
1431 CREATE USER "prometheus-sql-exporter";
1432 GRANT ALL PRIVILEGES ON DATABASE data TO "prometheus-sql-exporter";
1433 GRANT SELECT ON points TO "prometheus-sql-exporter";
1436 systemd.services.prometheus-sql-exporter.after = [ "postgresql.service" ];
1439 wait_for_unit("prometheus-sql-exporter.service")
1440 wait_for_open_port(9237)
1441 succeed("curl http://localhost:9237/metrics | grep -c 'sql_points{' | grep 2")
1450 wait_for_unit("prometheus-statsd-exporter.service")
1451 wait_for_open_port(9102)
1452 succeed("curl http://localhost:9102/metrics | grep 'statsd_exporter_build_info{'")
1453 wait_until_succeeds(
1454 "echo 'test.udp:1|c' > /dev/udp/localhost/9125 && \
1455 curl http://localhost:9102/metrics | grep 'test_udp 1'",
1458 wait_until_succeeds(
1459 "echo 'test.tcp:1|c' > /dev/tcp/localhost/9125 && \
1460 curl http://localhost:9102/metrics | grep 'test_tcp 1'",
1469 modemAddress = "localhost";
1472 systemd.services.prometheus-surfboard-exporter.after = [ "nginx.service" ];
1475 virtualHosts.localhost.locations."/cgi-bin/status".extraConfig = ''
1481 wait_for_unit("nginx.service")
1482 wait_for_open_port(80)
1483 wait_for_unit("prometheus-surfboard-exporter.service")
1484 wait_for_open_port(9239)
1485 succeed("curl -sSf localhost:9239/metrics | grep 'surfboard_up 1'")
1494 "--systemd.collector.enable-restart-count"
1497 metricProvider = { };
1499 wait_for_unit("prometheus-systemd-exporter.service")
1500 wait_for_open_port(9558)
1501 wait_until_succeeds(
1502 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1503 'systemd_unit_state{name="basic.target",state="active",type="target"} 1'
1507 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1508 'systemd_service_restart_total{name="prometheus-systemd-exporter.service"} 0'
1519 # Note: this does not connect the test environment to the Tor network.
1520 # Client, relay, bridge or exit connectivity are disabled by default.
1521 services.tor.enable = true;
1522 services.tor.settings.ControlPort = 9051;
1525 wait_for_unit("tor.service")
1526 wait_for_open_port(9051)
1527 wait_for_unit("prometheus-tor-exporter.service")
1528 wait_for_open_port(9130)
1529 succeed("curl -sSf localhost:9130/metrics | grep 'tor_version{.\\+} 1'")
1534 nodeName = "unpoller";
1535 exporterConfig.enable = true;
1536 exporterConfig.controllers = [{ }];
1538 wait_until_succeeds(
1539 'journalctl -eu prometheus-unpoller-exporter.service -o cat | grep "Connection Error"'
1547 unbound.host = "unix:///run/unbound/unbound.ctl";
1550 services.unbound = {
1552 localControlSocketPath = "/run/unbound/unbound.ctl";
1554 systemd.services.prometheus-unbound-exporter.serviceConfig = {
1555 SupplementaryGroups = [ "unbound" ];
1559 wait_for_unit("unbound.service")
1560 wait_for_unit("prometheus-unbound-exporter.service")
1561 wait_for_open_port(9167)
1562 wait_until_succeeds("curl -sSf localhost:9167/metrics | grep 'unbound_up 1'")
1572 systemd.services.prometheus-nginx-exporter.after = [ "v2ray.service" ];
1579 services = [ "StatsService" ];
1584 listen = "127.0.0.1";
1588 listen = "127.0.0.1";
1590 protocol = "dokodemo-door";
1591 settings = { address = "127.0.0.1"; };
1597 protocol = "freedom";
1600 protocol = "freedom";
1610 inboundTag = [ "api" ];
1611 outboundTag = "api";
1621 wait_for_unit("prometheus-v2ray-exporter.service")
1622 wait_for_open_port(9299)
1623 succeed("curl -sSf localhost:9299/scrape | grep 'v2ray_up 1'")
1630 instance = "/var/spool/varnish/varnish";
1634 systemd.services.prometheus-varnish-exporter.after = [
1637 services.varnish = {
1642 .host = "127.0.0.1";
1649 wait_for_unit("prometheus-varnish-exporter.service")
1650 wait_for_open_port(6081)
1651 wait_for_open_port(9131)
1652 succeed("curl -sSf http://localhost:9131/metrics | grep 'varnish_up 1'")
1657 snakeoil = import ./wireguard/snakeoil-keys.nix;
1658 publicKeyWithoutNewlines = replaceStrings [ "\n" ] [ "" ] snakeoil.peer1.publicKey;
1661 exporterConfig.enable = true;
1663 networking.wireguard.interfaces.wg0 = {
1664 ips = [ "10.23.42.1/32" "fc00::1/128" ];
1667 inherit (snakeoil.peer0) privateKey;
1670 allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ];
1672 inherit (snakeoil.peer1) publicKey;
1675 systemd.services.prometheus-wireguard-exporter.after = [ "wireguard-wg0.service" ];
1678 wait_for_unit("prometheus-wireguard-exporter.service")
1679 wait_for_open_port(9586)
1680 wait_until_succeeds(
1681 "curl -sSf http://localhost:9586/metrics | grep '${publicKeyWithoutNewlines}'"
1691 boot.supportedFilesystems = [ "zfs" ];
1692 networking.hostId = "7327ded7";
1695 wait_for_unit("prometheus-zfs-exporter.service")
1696 wait_for_unit("zfs.target")
1697 wait_for_open_port(9134)
1698 wait_until_succeeds("curl -f localhost:9134/metrics | grep 'zfs_scrape_collector_success{.*} 1'")
1704 (exporter: testConfig: (makeTest (
1706 nodeName = testConfig.nodeName or exporter;
1710 name = "prometheus-${exporter}-exporter";
1712 nodes.${nodeName} = mkMerge [{
1713 services.prometheus.exporters.${exporter} = testConfig.exporterConfig;
1714 } testConfig.metricProvider or { }];
1718 ${concatStringsSep "\n" (map (line:
1719 if builtins.any (b: b) [
1720 (builtins.match "^[[:space:]]*$" line != null)
1721 (builtins.substring 0 1 line == "#")
1722 (builtins.substring 0 1 line == " ")
1723 (builtins.substring 0 1 line == ")")
1726 else "${nodeName}.${line}"
1727 ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
1728 ${nodeName}.shutdown()
1731 meta = with maintainers; {
1732 maintainers = [ willibutz ];