diff options
author | Bas van Dijk <v.dijk.bas@gmail.com> | 2019-04-15 23:46:25 +0200 |
---|---|---|
committer | Bas van Dijk <v.dijk.bas@gmail.com> | 2019-04-16 08:09:38 +0200 |
commit | d1940beb3a0547d5892f0e063a515a3923a92be5 (patch) | |
tree | ae38ea6679ad70d139c829315429dddcbdbbeb87 /nixos/tests | |
parent | 888f32f32feba8ff183d713cb5467d3c51b625d5 (diff) | |
download | nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar.gz nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar.bz2 nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar.lz nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar.xz nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.tar.zst nixlib-d1940beb3a0547d5892f0e063a515a3923a92be5.zip |
nixos/prometheus/pushgateway: add module and test
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/prometheus-2.nix | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/nixos/tests/prometheus-2.nix b/nixos/tests/prometheus-2.nix index 5a4d8668cb87..d7035d49ad4d 100644 --- a/nixos/tests/prometheus-2.nix +++ b/nixos/tests/prometheus-2.nix @@ -3,15 +3,29 @@ import ./make-test.nix { nodes = { one = { pkgs, ... }: { + environment.systemPackages = [ pkgs.jq ]; services.prometheus2 = { enable = true; - scrapeConfigs = [{ - job_name = "prometheus"; - static_configs = [{ - targets = [ "127.0.0.1:9090" ]; - labels = { instance = "localhost"; }; - }]; - }]; + scrapeConfigs = [ + { + job_name = "prometheus"; + static_configs = [ + { + targets = [ "127.0.0.1:9090" ]; + labels = { instance = "localhost"; }; + } + ]; + } + { + job_name = "pushgateway"; + scrape_interval = "1s"; + static_configs = [ + { + targets = [ "127.0.0.1:9091" ]; + } + ]; + } + ]; rules = [ '' groups: @@ -22,6 +36,12 @@ import ./make-test.nix { '' ]; }; + services.prometheus.pushgateway = { + enable = true; + persistMetrics = true; + persistence.interval = "1s"; + stateDir = "prometheus-pushgateway"; + }; }; }; @@ -30,5 +50,18 @@ import ./make-test.nix { $one->waitForUnit("prometheus2.service"); $one->waitForOpenPort(9090); $one->succeed("curl -s http://127.0.0.1:9090/metrics"); + + # Let's test if pushing a metric to the pushgateway succeeds + # and whether that metric gets ingested by prometheus. + $one->waitForUnit("pushgateway.service"); + $one->succeed( + "echo 'some_metric 3.14' | " . + "curl --data-binary \@- http://127.0.0.1:9091/metrics/job/some_job"); + $one->waitUntilSucceeds( + "curl -sf 'http://127.0.0.1:9090/api/v1/query?query=some_metric' " . + "| jq '.data.result[0].value[1]' | grep '\"3.14\"'"); + + # Let's test if the pushgateway persists metrics to the configured location. + $one->waitUntilSucceeds("test -e /var/lib/prometheus-pushgateway/metrics"); ''; } |