forked from grafana/agent-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.river
58 lines (48 loc) · 1.6 KB
/
module.river
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
argument "targets" { }
argument "hostname" {
optional = true
// Match static mode's behavior for how the hostname was determined, where
// the $HOSTNAME environment variable took precedence over the
// machine-reported hostname.
default = coalesce(
env("HOSTNAME"),
constants.hostname,
)
}
export "output" {
value = discovery.relabel.host_filter.output
}
discovery.relabel "host_filter" {
targets = argument.targets.value
// Provide a set of labels which may indicate that the target comes from
// the same host as the one Grafana Agent is running on.
rule {
source_labels = [
// Labels from Consul SD.
"__meta_consul_node",
// Labels from Docker Swarm SD.
"__meta_dockerswarm_node_id",
"__meta_dockerswarm_node_hostname",
"__meta_dockerswarm_node_address",
// Labels from Kubernetes SD. Labels for `role: service` are omitted as
// service targets have labels merged with discovered pods.
"__meta_kubernetes_pod_node_name",
"__meta_kubernetes_node_name",
// Custom host label.
"__host__",
]
// Our in-memory string will be something like A;B;C;D;E;F, where any of
// the letters could be replaced with a label value or be empty if the
// label value did not exist.
//
// We want to search for one of the following:
//
// - localhost or 127.0.0.1
// - The hostname to check against.
//
// Where that text is either preceded by a colon (;B) or the start of the
// string (A), and succeeded by a colon (B;) or the end of the string (F).
regex = ".*(?:^|;)(localhost|127\\.0\\.0\\.1|" + argument.hostname.value + ")(?:;|$).*"
action = "keep"
}
}