blob: d7035d49ad4db44678f13daeb25cc83439f2fdb3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import ./make-test.nix {
name = "prometheus-2";
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"; };
}
];
}
{
job_name = "pushgateway";
scrape_interval = "1s";
static_configs = [
{
targets = [ "127.0.0.1:9091" ];
}
];
}
];
rules = [
''
groups:
- name: test
rules:
- record: testrule
expr: count(up{job="prometheus"})
''
];
};
services.prometheus.pushgateway = {
enable = true;
persistMetrics = true;
persistence.interval = "1s";
stateDir = "prometheus-pushgateway";
};
};
};
testScript = ''
startAll;
$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");
'';
}
|