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
100 lines (88 loc) · 3.19 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
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
package metrics
import (
"fmt"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/servicemonitor"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheusnodeexporter/info"
"github.com/caos/orbos/internal/operator/boom/labels"
)
func getLocalServiceMonitor(appName string, monitorMatchingLabels, serviceMatchingLabels map[string]string) *servicemonitor.Config {
relabelings := make([]*servicemonitor.ConfigRelabeling, 0)
relabeling := &servicemonitor.ConfigRelabeling{
Action: "replace",
Regex: "(.*)",
Replacement: "$1",
SourceLabels: []string{"__meta_kubernetes_pod_node_name"},
TargetLabel: "instance",
}
relabelings = append(relabelings, relabeling)
endpoint := &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
Relabelings: relabelings,
}
return &servicemonitor.Config{
Name: "prometheus-local-node-exporter-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
JobName: fmt.Sprintf("local-%s", appName),
MonitorMatchingLabels: monitorMatchingLabels,
ServiceMatchingLabels: serviceMatchingLabels,
}
}
func getIngestionServiceMonitor(appName string, monitorMatchingLabels, serviceMatchingLabels map[string]string) *servicemonitor.Config {
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__",
"mode",
"device",
"fstype",
"mountpoint",
},
Regex: "(node_cpu_seconds_total;idle;;;|(node_filesystem_avail_bytes|node_filesystem_size_bytes);;rootfs;rootfs;/|(node_memory_MemAvailable_bytes|node_memory_MemTotal_bytes|node_boot_time_seconds);;;;)",
}, {
Action: "labelkeep",
Regex: "__.+|job|instance|cpu",
}, {
Action: "replace",
SourceLabels: []string{"__name__"},
TargetLabel: "__name__",
Replacement: "dist_${1}",
}}
endpoint := &servicemonitor.ConfigEndpoint{
Port: "metrics",
Path: "/metrics",
HonorLabels: false,
Relabelings: relabelings,
MetricRelabelings: metricRelabelings,
}
return &servicemonitor.Config{
Name: "prometheus-ingestion-node-exporter-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
JobName: fmt.Sprintf("ingestion-%s", appName),
MonitorMatchingLabels: monitorMatchingLabels,
ServiceMatchingLabels: serviceMatchingLabels,
}
}
func GetServicemonitors(instanceName string) []*servicemonitor.Config {
appName := info.GetName()
appNameStr := appName.String()
monitorLabels := labels.GetMonitorLabels(instanceName, appName)
ls := labels.GetApplicationLabels(appName)
return []*servicemonitor.Config{
getLocalServiceMonitor(appNameStr, monitorLabels, ls),
getIngestionServiceMonitor(appNameStr, monitorLabels, ls),
}
}