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'"
183 extraFlags = [ "--web.collectd-push-path /collectd" ];
185 exporterTest = let postData = replaceStrings [ "\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)
237 succeed("curl -sSf 'http://localhost:9222/probe?target=nixos.org'")
244 scopes = [ "global" ];
245 socketPath = "/var/run/dovecot2/old-stats";
246 user = "root"; # <- don't use user root in production
249 services.dovecot2.enable = true;
252 wait_for_unit("prometheus-dovecot-exporter.service")
253 wait_for_open_port(9166)
255 "curl -sSf http://localhost:9166/metrics | grep 'dovecot_up{scope=\"global\"} 1'"
261 nodeName = "exportarr_sonarr";
264 url = "http://127.0.0.1:8989";
265 # testing for real data is tricky, because the api key can not be preconfigured
266 apiKeyFile = pkgs.writeText "dummy-api-key" "eccff6a992bc2e4b88e46d064b26bb4e";
269 wait_for_unit("prometheus-exportarr-sonarr-exporter.service")
270 wait_for_open_port(9707)
271 succeed("curl -sSf 'http://localhost:9707/metrics")
278 tokenPath = pkgs.writeText "token" "abc123";
281 # noop: fastly's exporter can't start without first talking to fastly
282 # see: https://github.com/peterbourgon/fastly-exporter/issues/87
289 # TODO add proper test case
294 wait_for_unit("prometheus-fritzbox-exporter.service")
295 wait_for_open_port(9133)
297 "curl -sSf http://localhost:9133/metrics | grep 'fritzbox_exporter_collect_errors 0'"
307 mappingSettings.mappings = [{
317 wait_for_unit("prometheus-graphite-exporter.service")
318 wait_for_open_port(9108)
319 wait_for_open_port(9109)
320 succeed("echo test.tcp.foo-bar 1234 $(date +%s) | nc -w1 localhost 9109")
321 succeed("curl -sSf http://localhost:9108/metrics | grep 'testing{author=\"foo-bar\",protocol=\"tcp\"} 1234'")
331 default = { username = "username"; password = "password"; };
336 wait_for_unit("prometheus-idrac-exporter.service")
337 wait_for_open_port(9348)
338 wait_until_succeeds("curl localhost:9348")
348 wait_for_unit("prometheus-influxdb-exporter.service")
349 wait_for_open_port(9122)
351 "curl -XPOST http://localhost:9122/write --data-binary 'influxdb_exporter,distro=nixos,added_in=21.09 value=1'"
354 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
358 "curl -sSf http://localhost:9122/metrics | grep 'nixos'"
368 wait_for_unit("prometheus-ipmi-exporter.service")
369 wait_for_open_port(9290)
371 "curl -sSf http://localhost:9290/metrics | grep 'ipmi_scrape_duration_seconds'"
381 systemd.services.prometheus-jitsi-exporter.after = [ "jitsi-videobridge2.service" ];
382 services.jitsi-videobridge = {
384 colibriRestApi = true;
388 wait_for_unit("jitsi-videobridge2.service")
389 wait_for_open_port(8080)
390 wait_for_unit("prometheus-jitsi-exporter.service")
391 wait_for_open_port(9700)
393 'journalctl -eu prometheus-jitsi-exporter.service -o cat | grep "key=participants"'
395 succeed("curl -sSf 'localhost:9700/metrics' | grep 'jitsi_participants 0'")
402 url = "http://localhost";
403 configFile = pkgs.writeText "json-exporter-conf.json" (builtins.toJSON {
407 { name = "json_test_metric"; path = "{ .test }"; }
414 systemd.services.prometheus-json-exporter.after = [ "nginx.service" ];
417 virtualHosts.localhost.locations."/".extraConfig = ''
418 return 200 "{\"test\":1}";
423 wait_for_unit("nginx.service")
424 wait_for_open_port(80)
425 wait_for_unit("prometheus-json-exporter.service")
426 wait_for_open_port(7979)
428 "curl -sSf 'localhost:7979/probe?target=http://localhost' | grep 'json_test_metric 1'"
434 controlSocketPathV4 = "/run/kea-dhcp4/dhcp4.sock";
435 controlSocketPathV6 = "/run/kea-dhcp6/dhcp6.sock";
440 controlSocketPaths = [
451 socket-type = "unix";
452 socket-name = controlSocketPathV4;
460 socket-type = "unix";
461 socket-name = controlSocketPathV6;
469 wait_for_unit("kea-dhcp4-server.service")
470 wait_for_unit("kea-dhcp6-server.service")
471 wait_for_file("${controlSocketPathV4}")
472 wait_for_file("${controlSocketPathV6}")
473 wait_for_unit("prometheus-kea-exporter.service")
474 wait_for_open_port(9547)
476 "curl --fail localhost:9547/metrics | grep 'packets_received_total'"
488 extraArgs = [ "-v" ];
489 settingsFile = pkgs.writeText "knot.conf" ''
495 global-module: mod-stats
498 journal-db: /var/lib/knot/journal
499 kasp-db: /var/lib/knot/kasp
500 timer-db: /var/lib/knot/timer
501 zonefile-load: difference
502 storage: ${pkgs.buildEnv {
505 (pkgs.writeTextDir "test.zone" ''
506 @ SOA ns.example.com. noc.example.com. 2019031301 86400 7200 3600000 172800
522 module: mod-stats/custom
527 wait_for_unit("knot.service")
528 wait_for_unit("prometheus-knot-exporter.service")
529 wait_for_open_port(9433)
530 succeed("curl -sSf 'localhost:9433' | grep '2\.019031301'")
535 # A hardware device is required to properly test this exporter, so just
536 # perform a couple of basic sanity checks that the exporter is running
537 # and requires a target, but cannot reach a specified target.
542 wait_for_unit("prometheus-keylight-exporter.service")
543 wait_for_open_port(9288)
545 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics | grep '400'"
548 "curl -sS --write-out '%{http_code}' -o /dev/null http://localhost:9288/metrics?target=nosuchdevice | grep '500'"
556 lndTlsPath = "/var/lib/lnd/tls.cert";
557 lndMacaroonDir = "/var/lib/lnd";
558 extraFlags = [ "--lnd.network=regtest" ];
561 systemd.services.prometheus-lnd-exporter.serviceConfig.RestartSec = 15;
562 systemd.services.prometheus-lnd-exporter.after = [ "lnd.service" ];
563 services.bitcoind.regtest = {
566 rpcauth=bitcoinrpc:e8fe33f797e698ac258c16c8d7aadfbe$872bdb8f4d787367c26bcfd75e6c23c4f19d44a69f5d1ad329e5adf3f82710f7
567 zmqpubrawblock=tcp://127.0.0.1:28332
568 zmqpubrawtx=tcp://127.0.0.1:28333
570 extraCmdlineOptions = [ "-regtest" ];
572 systemd.services.lnd = {
573 serviceConfig.ExecStart = ''
574 ${pkgs.lnd}/bin/lnd \
575 --datadir=/var/lib/lnd \
576 --tlscertpath=/var/lib/lnd/tls.cert \
577 --tlskeypath=/var/lib/lnd/tls.key \
578 --logdir=/var/log/lnd \
581 --bitcoin.node=bitcoind \
582 --bitcoind.rpcuser=bitcoinrpc \
583 --bitcoind.rpcpass=hunter2 \
584 --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 \
585 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 \
586 --readonlymacaroonpath=/var/lib/lnd/readonly.macaroon
588 serviceConfig.StateDirectory = "lnd";
589 wantedBy = [ "multi-user.target" ];
590 after = [ "network.target" ];
592 # initialize wallet, creates macaroon needed by exporter
593 systemd.services.lnd.postStart = ''
594 ${pkgs.curl}/bin/curl \
597 --retry-connrefused \
598 --cacert /var/lib/lnd/tls.cert \
600 https://localhost:8080/v1/genseed | ${pkgs.jq}/bin/jq -c '.cipher_seed_mnemonic' > /tmp/seed
601 ${pkgs.curl}/bin/curl \
604 --retry-connrefused \
605 --cacert /var/lib/lnd/tls.cert \
607 -d "{\"wallet_password\": \"asdfasdfasdf\", \"cipher_seed_mnemonic\": $(cat /tmp/seed | tr -d '\n')}" \
608 https://localhost:8080/v1/initwallet
612 wait_for_unit("lnd.service")
613 wait_for_open_port(10009)
614 wait_for_unit("prometheus-lnd-exporter.service")
615 wait_for_open_port(9092)
616 succeed("curl -sSf localhost:9092/metrics | grep '^lnd_peer_count'")
624 monitoringInterval = "2s";
625 mailCheckTimeout = "10s";
628 server = "localhost";
630 from = "mail-exporter@localhost";
631 to = "mail-exporter@localhost";
632 detectionDir = "/var/spool/mail/mail-exporter/new";
637 services.postfix.enable = true;
638 systemd.services.prometheus-mail-exporter = {
639 after = [ "postfix.service" ];
640 requires = [ "postfix.service" ];
643 "${pkgs.writeShellScript "create-maildir" ''
644 mkdir -p -m 0700 mail-exporter/new
649 ReadWritePaths = "/var/spool/mail";
650 WorkingDirectory = "/var/spool/mail";
653 users.users.mailexporter = {
655 group = "mailexporter";
657 users.groups.mailexporter = {};
660 wait_for_unit("postfix.service")
661 wait_for_unit("prometheus-mail-exporter.service")
662 wait_for_open_port(9225)
664 "curl -sSf http://localhost:9225/metrics | grep 'mail_deliver_success{configname=\"testserver\"} 1'"
672 extraFlags = [ "-timeout=1s" ];
677 address = "192.168.42.48";
701 wait_for_unit("prometheus-mikrotik-exporter.service")
702 wait_for_open_port(9436)
704 "curl -sSf http://localhost:9436/metrics | grep 'mikrotik_scrape_collector_success{device=\"router\"} 0'"
715 # ModemManager is installed when NetworkManager is enabled. Ensure it is
716 # started and is wanted by NM and the exporter to start everything up
717 # in the right order.
718 networking.networkmanager.enable = true;
719 systemd.services.ModemManager = {
721 wantedBy = [ "NetworkManager.service" "prometheus-modemmanager-exporter.service" ];
725 wait_for_unit("ModemManager.service")
726 wait_for_unit("prometheus-modemmanager-exporter.service")
727 wait_for_open_port(9539)
729 "curl -sSf http://localhost:9539/metrics | grep 'modemmanager_info'"
737 runAsLocalSuperUser = true;
738 configFile = pkgs.writeText "test-prometheus-exporter-mysqld-config.my-cnf" ''
741 password = snakeoilpassword
747 package = pkgs.mariadb;
748 initialScript = pkgs.writeText "mysql-init-script.sql" ''
749 CREATE USER 'exporter'@'localhost'
750 IDENTIFIED BY 'snakeoilpassword'
751 WITH MAX_USER_CONNECTIONS 3;
752 GRANT PROCESS, REPLICATION CLIENT, SLAVE MONITOR, SELECT ON *.* TO 'exporter'@'localhost';
757 wait_for_unit("prometheus-mysqld-exporter.service")
758 wait_for_open_port(9104)
759 wait_for_unit("mysql.service")
760 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 1'")
761 systemctl("stop mysql.service")
762 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 0'")
763 systemctl("start mysql.service")
764 wait_for_unit("mysql.service")
765 succeed("curl -sSf http://localhost:9104/metrics | grep 'mysql_up 1'")
772 passwordFile = "/var/nextcloud-pwfile";
773 url = "http://localhost";
776 systemd.services.nc-pwfile =
778 passfile = (pkgs.writeText "pwfile" "snakeoilpw");
781 requiredBy = [ "prometheus-nextcloud-exporter.service" ];
782 before = [ "prometheus-nextcloud-exporter.service" ];
783 serviceConfig.ExecStart = ''
784 ${pkgs.coreutils}/bin/install -o nextcloud-exporter -m 0400 ${passfile} /var/nextcloud-pwfile
789 virtualHosts."localhost" = {
790 basicAuth.nextcloud-exporter = "snakeoilpw";
792 root = "${pkgs.prometheus-nextcloud-exporter.src}/serverinfo/testdata";
793 tryFiles = "/negative-space.json =404";
799 wait_for_unit("nginx.service")
800 wait_for_unit("prometheus-nextcloud-exporter.service")
801 wait_for_open_port(9205)
802 succeed("curl -sSf http://localhost:9205/metrics | grep 'nextcloud_up 1'")
814 virtualHosts."test".extraConfig = "return 204;";
818 wait_for_unit("nginx.service")
819 wait_for_unit("prometheus-nginx-exporter.service")
820 wait_for_open_port(9113)
821 succeed("curl -sSf http://localhost:9113/metrics | grep 'nginx_up 1'")
834 files = [ "/var/log/nginx/filelogger.access.log" ];
841 listen_address = "udp://127.0.0.1:10000";
856 server_name filelogger.local;
857 access_log /var/log/nginx/filelogger.access.log;
861 server_name syslogger.local;
862 access_log syslog:server=127.0.0.1:10000,tag=nginx,severity=info;
868 wait_for_unit("nginx.service")
869 wait_for_unit("prometheus-nginxlog-exporter.service")
870 wait_for_open_port(9117)
871 wait_for_open_port(80)
872 wait_for_open_port(81)
873 succeed("curl http://localhost")
876 "curl -sSf http://localhost:9117/metrics | grep 'filelogger_http_response_count_total' | grep 1"
878 succeed("curl http://localhost:81")
881 "curl -sSf http://localhost:9117/metrics | grep 'syslogger_http_response_count_total' | grep 1"
891 wait_for_unit("prometheus-node-exporter.service")
892 wait_for_open_port(9100)
894 "curl -sSf http://localhost:9100/metrics | grep 'node_exporter_build_info{.\\+} 1'"
902 ldapCredentialFile = "${pkgs.writeText "exporter.yml" ''
903 ldapUser: "cn=root,dc=example"
904 ldapPass: "notapassword"
908 services.openldap = {
910 settings.children = {
911 "cn=schema".includes = [
912 "${pkgs.openldap}/etc/schema/core.ldif"
913 "${pkgs.openldap}/etc/schema/cosine.ldif"
914 "${pkgs.openldap}/etc/schema/inetorgperson.ldif"
915 "${pkgs.openldap}/etc/schema/nis.ldif"
917 "olcDatabase={1}mdb" = {
919 objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
920 olcDatabase = "{1}mdb";
921 olcDbDirectory = "/var/db/openldap";
922 olcSuffix = "dc=example";
925 base64 = "Y249cm9vdCxkYz1leGFtcGxl";
928 path = "${pkgs.writeText "rootpw" "notapassword"}";
932 "olcDatabase={2}monitor".attrs = {
933 objectClass = [ "olcDatabaseConfig" ];
934 olcDatabase = "{2}monitor";
935 olcAccess = [ "to dn.subtree=cn=monitor by users read" ];
938 declarativeContents."dc=example" = ''
943 dn: ou=users,dc=example
944 objectClass: organizationalUnit
950 wait_for_unit("prometheus-openldap-exporter.service")
951 wait_for_open_port(389)
952 wait_for_open_port(9330)
954 "curl -sSf http://localhost:9330/metrics | grep 'openldap_scrape{result=\"ok\"} 1'"
963 statusPaths = [ "/run/openvpn-test" ];
966 users.groups.openvpn = { };
967 services.openvpn.servers.test = {
970 status /run/openvpn-test
973 up = "chmod g+r /run/openvpn-test";
975 systemd.services."openvpn-test".serviceConfig.Group = "openvpn";
978 wait_for_unit("openvpn-test.service")
979 wait_for_unit("prometheus-openvpn-exporter.service")
980 succeed("curl -sSf http://localhost:9176/metrics | grep 'openvpn_up{.*} 1'")
987 connectionStringFile = pkgs.writeText "connection.conf" "postgres://admin:@localhost:6432/pgbouncer?sslmode=disable";
991 services.postgresql.enable = true;
992 services.pgbouncer = {
993 # https://github.com/prometheus-community/pgbouncer_exporter#pgbouncer-configuration
994 ignoreStartupParameters = "extra_float_digits";
997 databases = { postgres = "host=/run/postgresql/ port=5432 auth_user=postgres dbname=postgres"; };
1003 wait_for_unit("postgresql.service")
1004 wait_for_unit("pgbouncer.service")
1005 wait_for_unit("prometheus-pgbouncer-exporter.service")
1006 wait_for_open_port(9127)
1007 succeed("curl -sSf http://localhost:9127/metrics | grep 'pgbouncer_up 1'")
1009 "curl -sSf http://localhost:9127/metrics | grep 'pgbouncer_config_max_client_connections 99'"
1015 nodeName = "php_fpm";
1018 environmentFile = pkgs.writeTextFile {
1019 name = "/tmp/prometheus-php-fpm-exporter.env";
1021 PHP_FPM_SCRAPE_URI="tcp://127.0.0.1:9000/status"
1026 users.users."php-fpm-exporter" = {
1027 isSystemUser = true;
1028 group = "php-fpm-exporter";
1030 users.groups."php-fpm-exporter" = {};
1031 services.phpfpm.pools."php-fpm-exporter" = {
1032 user = "php-fpm-exporter";
1033 group = "php-fpm-exporter";
1036 "pm.max_children" = 32;
1037 "pm.max_requests" = 500;
1038 "pm.start_servers" = 2;
1039 "pm.min_spare_servers" = 2;
1040 "pm.max_spare_servers" = 5;
1041 "pm.status_path" = "/status";
1042 "listen" = "127.0.0.1:9000";
1043 "listen.allowed_clients" = "127.0.0.1";
1045 phpEnv."PATH" = makeBinPath [ pkgs.php ];
1049 wait_for_unit("phpfpm-php-fpm-exporter.service")
1050 wait_for_unit("prometheus-php-fpm-exporter.service")
1051 succeed("curl -sSf http://localhost:9253/metrics | grep 'phpfpm_up{.*} 1'")
1060 services.postfix.enable = true;
1063 wait_for_unit("prometheus-postfix-exporter.service")
1064 wait_for_file("/var/lib/postfix/queue/public/showq")
1065 wait_for_open_port(9154)
1066 wait_until_succeeds(
1067 "curl -sSf http://localhost:9154/metrics | grep 'postfix_up{path=\"/var/lib/postfix/queue/public/showq\"} 1'"
1070 "curl -sSf http://localhost:9154/metrics | grep 'postfix_smtpd_connects_total 0'"
1072 succeed("curl -sSf http://localhost:9154/metrics | grep 'postfix_up{.*} 1'")
1079 runAsLocalSuperUser = true;
1082 services.postgresql.enable = true;
1085 wait_for_unit("prometheus-postgres-exporter.service")
1086 wait_for_open_port(9187)
1087 wait_for_unit("postgresql.service")
1089 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
1091 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
1092 systemctl("stop postgresql.service")
1094 "curl -sSf http://localhost:9187/metrics | grep -v 'pg_exporter_last_scrape_error 0'"
1096 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 0'")
1097 systemctl("start postgresql.service")
1098 wait_for_unit("postgresql.service")
1100 "curl -sSf http://localhost:9187/metrics | grep 'pg_exporter_last_scrape_error 0'"
1102 succeed("curl -sSf http://localhost:9187/metrics | grep 'pg_up 1'")
1109 settings.process_names = [
1110 # Remove nix store path from process name
1111 { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
1115 wait_for_unit("prometheus-process-exporter.service")
1116 wait_for_open_port(9256)
1117 wait_until_succeeds(
1118 "curl -sSf localhost:9256/metrics | grep -q '{}'".format(
1119 'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter '
1126 pveExporterEnvFile = pkgs.writeTextFile {
1129 PVE_USER="test_user@pam"
1130 PVE_PASSWORD="hunter3"
1131 PVE_VERIFY_SSL="false"
1137 environmentFile = pveExporterEnvFile;
1140 wait_for_unit("prometheus-pve-exporter.service")
1141 wait_for_open_port(9221)
1142 wait_until_succeeds("curl localhost:9221")
1147 nodeName = "py_air_control";
1150 deviceHostname = "127.0.0.1";
1153 wait_for_unit("prometheus-py-air-control-exporter.service")
1154 wait_for_open_port(9896)
1156 "curl -sSf http://localhost:9896/metrics | grep 'py_air_control_sampling_error_total'"
1165 metricProvider.services.redis.servers."".enable = true;
1167 wait_for_unit("redis.service")
1168 wait_for_unit("prometheus-redis-exporter.service")
1169 wait_for_open_port(6379)
1170 wait_for_open_port(9121)
1171 wait_until_succeeds("curl -sSf localhost:9121/metrics | grep 'redis_up 1'")
1180 services.rspamd.enable = true;
1183 wait_for_unit("rspamd.service")
1184 wait_for_unit("prometheus-rspamd-exporter.service")
1185 wait_for_open_port(11334)
1186 wait_for_open_port(7980)
1187 wait_until_succeeds(
1188 "curl -sSf 'localhost:7980/probe?target=http://localhost:11334/stat' | grep 'rspamd_scanned{host=\"rspamd\"} 0'"
1198 # Mock rtl_433 binary to return a dummy metric stream.
1199 nixpkgs.overlays = [
1201 rtl_433 = self.runCommand "rtl_433" { } ''
1203 cat <<EOF > "$out/bin/rtl_433"
1206 printf '{"time" : "2020-04-26 13:37:42", "model" : "zopieux", "id" : 55, "channel" : 3, "temperature_C" : 18.000}\n'
1210 chmod +x "$out/bin/rtl_433"
1216 wait_for_unit("prometheus-rtl_433-exporter.service")
1217 wait_for_open_port(9550)
1218 wait_until_succeeds(
1219 "curl -sSf localhost:9550/metrics | grep '{}'".format(
1220 'rtl_433_temperature_celsius{channel="3",id="55",location="",model="zopieux"} 18'
1230 baseUrl = "http://localhost:8080";
1231 apiKeyFile = "/var/sabnzbd-apikey";
1236 services.sabnzbd.enable = true;
1238 # unrar is required for sabnzbd
1239 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "unrar" ];
1241 # extract the generated api key before starting
1242 systemd.services.sabnzbd-apikey = {
1243 requires = [ "sabnzbd.service" ];
1244 after = [ "sabnzbd.service" ];
1245 requiredBy = [ "prometheus-sabnzbd-exporter.service" ];
1246 before = [ "prometheus-sabnzbd-exporter.service" ];
1248 grep -Po '^api_key = \K.+' /var/lib/sabnzbd/sabnzbd.ini > /var/sabnzbd-apikey
1254 wait_for_unit("sabnzbd.service")
1255 wait_for_unit("prometheus-sabnzbd-exporter.service")
1256 wait_for_open_port(8080)
1257 wait_for_open_port(9387)
1258 wait_until_succeeds(
1259 "curl -sSf 'localhost:9387/metrics' | grep 'sabnzbd_queue_size{sabnzbd_instance=\"http://localhost:8080\"} 0.0'"
1269 boot.kernelModules = [ "intel_rapl_common" ];
1272 wait_for_unit("prometheus-scaphandre-exporter.service")
1273 wait_for_open_port(8080)
1274 wait_until_succeeds(
1275 "curl -sSf 'localhost:8080/metrics'"
1283 metrics-file = "${pkgs.writeText "test.json" ''{}''}";
1286 wait_for_unit("prometheus-shelly-exporter.service")
1287 wait_for_open_port(9784)
1288 wait_until_succeeds(
1289 "curl -sSf 'localhost:9784/metrics'"
1297 settings.scripts = [
1298 { name = "success"; script = "sleep 1"; }
1302 wait_for_unit("prometheus-script-exporter.service")
1303 wait_for_open_port(9172)
1304 wait_until_succeeds(
1305 "curl -sSf 'localhost:9172/probe?name=success' | grep -q '{}'".format(
1306 'script_success{script="success"} 1'
1320 wait_until_succeeds(
1321 'journalctl -eu prometheus-smartctl-exporter.service -o cat | grep "Unable to detect device type"'
1329 hosts = [ "127.0.0.1" ];
1332 wait_for_unit("prometheus-smokeping-exporter.service")
1333 wait_for_open_port(9374)
1334 wait_until_succeeds(
1335 "curl -sSf localhost:9374/metrics | grep '{}' | grep -v ' 0$'".format(
1336 'smokeping_requests_total{host="127.0.0.1",ip="127.0.0.1",source=""} '
1339 wait_until_succeeds(
1340 "curl -sSf localhost:9374/metrics | grep '{}'".format(
1341 'smokeping_response_ttl{host="127.0.0.1",ip="127.0.0.1",source=""}'
1350 configuration.default = {
1352 auth.community = "public";
1356 wait_for_unit("prometheus-snmp-exporter.service")
1357 wait_for_open_port(9116)
1358 succeed("curl -sSf localhost:9116/metrics | grep 'snmp_request_errors_total 0'")
1364 configuration.jobs.points = {
1367 "postgres://prometheus-sql-exporter@/data?host=/run/postgresql&sslmode=disable"
1371 labels = [ "name" ];
1372 help = "Amount of points accumulated per person";
1373 values = [ "amount" ];
1374 query = "SELECT SUM(amount) as amount, name FROM points GROUP BY name";
1379 user = "prometheus-sql-exporter";
1382 services.postgresql = {
1384 initialScript = builtins.toFile "init.sql" ''
1385 CREATE DATABASE data;
1387 CREATE TABLE points (amount INT, name TEXT);
1388 INSERT INTO points(amount, name) VALUES (1, 'jack');
1389 INSERT INTO points(amount, name) VALUES (2, 'jill');
1390 INSERT INTO points(amount, name) VALUES (3, 'jack');
1392 CREATE USER "prometheus-sql-exporter";
1393 GRANT ALL PRIVILEGES ON DATABASE data TO "prometheus-sql-exporter";
1394 GRANT SELECT ON points TO "prometheus-sql-exporter";
1397 systemd.services.prometheus-sql-exporter.after = [ "postgresql.service" ];
1400 wait_for_unit("prometheus-sql-exporter.service")
1401 wait_for_open_port(9237)
1402 succeed("curl http://localhost:9237/metrics | grep -c 'sql_points{' | grep 2")
1411 wait_for_unit("prometheus-statsd-exporter.service")
1412 wait_for_open_port(9102)
1413 succeed("curl http://localhost:9102/metrics | grep 'statsd_exporter_build_info{'")
1414 wait_until_succeeds(
1415 "echo 'test.udp:1|c' > /dev/udp/localhost/9125 && \
1416 curl http://localhost:9102/metrics | grep 'test_udp 1'",
1419 wait_until_succeeds(
1420 "echo 'test.tcp:1|c' > /dev/tcp/localhost/9125 && \
1421 curl http://localhost:9102/metrics | grep 'test_tcp 1'",
1430 modemAddress = "localhost";
1433 systemd.services.prometheus-surfboard-exporter.after = [ "nginx.service" ];
1436 virtualHosts.localhost.locations."/cgi-bin/status".extraConfig = ''
1442 wait_for_unit("nginx.service")
1443 wait_for_open_port(80)
1444 wait_for_unit("prometheus-surfboard-exporter.service")
1445 wait_for_open_port(9239)
1446 succeed("curl -sSf localhost:9239/metrics | grep 'surfboard_up 1'")
1455 "--systemd.collector.enable-restart-count"
1458 metricProvider = { };
1460 wait_for_unit("prometheus-systemd-exporter.service")
1461 wait_for_open_port(9558)
1462 wait_until_succeeds(
1463 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1464 'systemd_unit_state{name="basic.target",state="active",type="target"} 1'
1468 "curl -sSf localhost:9558/metrics | grep '{}'".format(
1469 'systemd_service_restart_total{name="prometheus-systemd-exporter.service"} 0'
1480 # Note: this does not connect the test environment to the Tor network.
1481 # Client, relay, bridge or exit connectivity are disabled by default.
1482 services.tor.enable = true;
1483 services.tor.settings.ControlPort = 9051;
1486 wait_for_unit("tor.service")
1487 wait_for_open_port(9051)
1488 wait_for_unit("prometheus-tor-exporter.service")
1489 wait_for_open_port(9130)
1490 succeed("curl -sSf localhost:9130/metrics | grep 'tor_version{.\\+} 1'")
1495 nodeName = "unpoller";
1496 exporterConfig.enable = true;
1497 exporterConfig.controllers = [{ }];
1499 wait_until_succeeds(
1500 'journalctl -eu prometheus-unpoller-exporter.service -o cat | grep "Connection Error"'
1508 unbound.host = "unix:///run/unbound/unbound.ctl";
1511 services.unbound = {
1513 localControlSocketPath = "/run/unbound/unbound.ctl";
1515 systemd.services.prometheus-unbound-exporter.serviceConfig = {
1516 SupplementaryGroups = [ "unbound" ];
1520 wait_for_unit("unbound.service")
1521 wait_for_unit("prometheus-unbound-exporter.service")
1522 wait_for_open_port(9167)
1523 wait_until_succeeds("curl -sSf localhost:9167/metrics | grep 'unbound_up 1'")
1533 systemd.services.prometheus-nginx-exporter.after = [ "v2ray.service" ];
1540 services = [ "StatsService" ];
1545 listen = "127.0.0.1";
1549 listen = "127.0.0.1";
1551 protocol = "dokodemo-door";
1552 settings = { address = "127.0.0.1"; };
1558 protocol = "freedom";
1561 protocol = "freedom";
1571 inboundTag = [ "api" ];
1572 outboundTag = "api";
1582 wait_for_unit("prometheus-v2ray-exporter.service")
1583 wait_for_open_port(9299)
1584 succeed("curl -sSf localhost:9299/scrape | grep 'v2ray_up 1'")
1591 instance = "/var/spool/varnish/varnish";
1595 systemd.services.prometheus-varnish-exporter.after = [
1598 services.varnish = {
1603 .host = "127.0.0.1";
1610 wait_for_unit("prometheus-varnish-exporter.service")
1611 wait_for_open_port(6081)
1612 wait_for_open_port(9131)
1613 succeed("curl -sSf http://localhost:9131/metrics | grep 'varnish_up 1'")
1618 snakeoil = import ./wireguard/snakeoil-keys.nix;
1619 publicKeyWithoutNewlines = replaceStrings [ "\n" ] [ "" ] snakeoil.peer1.publicKey;
1622 exporterConfig.enable = true;
1624 networking.wireguard.interfaces.wg0 = {
1625 ips = [ "10.23.42.1/32" "fc00::1/128" ];
1628 inherit (snakeoil.peer0) privateKey;
1631 allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ];
1633 inherit (snakeoil.peer1) publicKey;
1636 systemd.services.prometheus-wireguard-exporter.after = [ "wireguard-wg0.service" ];
1639 wait_for_unit("prometheus-wireguard-exporter.service")
1640 wait_for_open_port(9586)
1641 wait_until_succeeds(
1642 "curl -sSf http://localhost:9586/metrics | grep '${publicKeyWithoutNewlines}'"
1652 boot.supportedFilesystems = [ "zfs" ];
1653 networking.hostId = "7327ded7";
1656 wait_for_unit("prometheus-zfs-exporter.service")
1657 wait_for_unit("zfs.target")
1658 wait_for_open_port(9134)
1659 wait_until_succeeds("curl -f localhost:9134/metrics | grep 'zfs_scrape_collector_success{.*} 1'")
1665 (exporter: testConfig: (makeTest (
1667 nodeName = testConfig.nodeName or exporter;
1671 name = "prometheus-${exporter}-exporter";
1673 nodes.${nodeName} = mkMerge [{
1674 services.prometheus.exporters.${exporter} = testConfig.exporterConfig;
1675 } testConfig.metricProvider or { }];
1679 ${concatStringsSep "\n" (map (line:
1680 if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")")
1682 else "${nodeName}.${line}"
1683 ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
1684 ${nodeName}.shutdown()
1687 meta = with maintainers; {
1688 maintainers = [ willibutz ];