blob: a64577d549ec1e7f4cf25d62f77a657473b362e3 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
{
extraModules,
pkgs,
vhack,
...
}: let
prometheusMain = "prometheus.server2.server.org";
remoteWriteTo = {
url = "https://${prometheusMain}";
};
promPort = 3001;
in
vhack.runTest {
name = "monitoring";
serverDomains = [
{server2 = prometheusMain;}
];
nodes = {
server2 = {config, ...}: {
imports =
extraModules
++ [
../../../../modules
];
environment.systemPackages = [
pkgs.curl
];
vhack = {
monitoring = {
prometheus = {
enable = true;
port = promPort;
remoteWriteReceiver = prometheusMain;
};
};
};
};
server3 = {config, ...}: {
imports =
extraModules
++ [
../../../../modules
];
vhack = {
monitoring = {
prometheus = {
enable = true;
port = promPort;
inherit remoteWriteTo;
};
};
};
};
server4 = {config, ...}: {
imports =
extraModules
++ [
../../../../modules
];
vhack = {
monitoring = {
prometheus = {
enable = true;
port = promPort;
inherit remoteWriteTo;
};
};
};
};
};
services = [
{server2 = "prometheus.service";}
{server3 = "prometheus.service";}
{server4 = "prometheus.service";}
];
testScript = {...}:
# Python
''
import json, time
# Give the Prometheus servers some time to generate metrics and sync with the main
# one.
time.sleep(1)
metrics = server2.succeed("${pkgs.writeShellScript "query-metrics" ''
curl --silent \
http://127.0.0.1:${toString promPort}/api/v1/query?query="go_gc_cleanups_queued_cleanups_total"
''}")
metrics = json.loads(metrics)
hosts = []
for result in metrics["data"]["result"]:
server2.log(json.dumps(result,indent=4))
hosts.append(result["metric"]["hostname"])
hosts.sort()
assert hosts == ["server2", "server3", "server4"], f"Not all hosts used the remote write (got {hosts})"
'';
}
|