vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / prometheus / remote-write.nix
blob24092b9fb88dadda5eba621b6ddc0cbf2631a482
1 import ../make-test-python.nix ({ lib, pkgs, ... }:
4   name = "prometheus-remote-write";
6   nodes = {
7     receiver = { config, pkgs, ... }: {
8       environment.systemPackages = [ pkgs.jq ];
10       networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
12       services.prometheus = {
13         enable = true;
14         globalConfig.scrape_interval = "2s";
16         extraFlags = [ "--web.enable-remote-write-receiver" ];
17       };
18     };
20     prometheus = { config, pkgs, ... }: {
21       environment.systemPackages = [ pkgs.jq ];
23       networking.firewall.allowedTCPPorts = [ config.services.prometheus.port ];
25       services.prometheus = {
26         enable = true;
27         globalConfig.scrape_interval = "2s";
29         remoteWrite = [
30           {
31             url = "http://receiver:9090/api/v1/write";
32           }
33         ];
35         scrapeConfigs = [
36           {
37             job_name = "node";
38             static_configs = [
39               {
40                 targets = [
41                   "node:${toString config.services.prometheus.exporters.node.port}"
42                 ];
43               }
44             ];
45           }
46         ];
47       };
48     };
50     node = { config, pkgs, ... }: {
51       services.prometheus.exporters.node = {
52         enable = true;
53         openFirewall = true;
54       };
55     };
56   };
58   testScript = ''
59     node.wait_for_unit("prometheus-node-exporter")
60     node.wait_for_open_port(9100)
62     for machine in prometheus, receiver:
63       machine.wait_for_unit("prometheus")
64       machine.wait_for_open_port(9090)
66     # Verify both servers got the same data from the exporter
67     for machine in prometheus, receiver:
68       machine.wait_until_succeeds(
69         "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=node_exporter_build_info\{instance=\"node:9100\"\}' | "
70         + "jq '.data.result[0].value[1]' | grep '\"1\"'"
71       )
72   '';