This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
servicemonitor.go
65 lines (57 loc) · 1.92 KB
/
servicemonitor.go
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
package metrics
import (
"fmt"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/servicemonitor"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheussystemdexporter/info"
"github.com/caos/orbos/internal/operator/boom/labels"
)
func GetServicemonitor(instanceName string) *servicemonitor.Config {
appName := info.GetName()
monitorLabels := labels.GetMonitorLabels(instanceName, appName)
ls := labels.GetApplicationLabels(appName)
relabelings := []*servicemonitor.ConfigRelabeling{{
Action: "replace",
SourceLabels: []string{"__meta_kubernetes_pod_node_name"},
TargetLabel: "instance",
}, {
Action: "replace",
SourceLabels: []string{"job"},
TargetLabel: "job",
Replacement: "caos_remote_${1}",
}, {
Action: "labeldrop",
Regex: "(container|endpoint|namespace|pod)",
}}
metricRelabelings := []*servicemonitor.ConfigRelabeling{{
Action: "keep",
SourceLabels: []string{
"__name__",
"state",
"name",
},
Regex: `(systemd_unit_state;active;(docker\.service|firewalld\.service|keepalived\.service|kubelet\.service|nginx\.service|node-agentd\.service|sshd\.service))`,
}, {
Action: "replace",
SourceLabels: []string{"__name__"},
TargetLabel: "__name__",
Regex: "systemd_unit_state",
Replacement: "dist_systemd_unit_active",
}, {
Action: "labelkeep",
Regex: "__.+|job|instance|name",
}}
endpoint := &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
HonorLabels: false,
Relabelings: relabelings,
MetricRelabelings: metricRelabelings,
}
return &servicemonitor.Config{
Name: "prometheus-ingestion-systemd-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
JobName: fmt.Sprintf("ingestion-%s", appName),
MonitorMatchingLabels: monitorLabels,
ServiceMatchingLabels: ls,
}
}