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
95 lines (83 loc) · 3.16 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
package metrics
import (
"github.com/caos/orbos/internal/operator/boom/application/applications/kubestatemetrics/info"
"github.com/caos/orbos/internal/operator/boom/application/applications/prometheus/servicemonitor"
"github.com/caos/orbos/internal/operator/boom/labels"
)
func getLocalServiceMonitor(monitorMatchingLabels, serviceMatchingLabels map[string]string) *servicemonitor.Config {
relabelings := make([]*servicemonitor.ConfigRelabeling, 0)
relabeling := &servicemonitor.ConfigRelabeling{
Action: "labeldrop",
Regex: "(pod|service|endpoint|namespace)",
}
relabelings = append(relabelings, relabeling)
endpoint := &servicemonitor.ConfigEndpoint{
Port: "http",
Path: "/metrics",
HonorLabels: true,
Relabelings: relabelings,
}
return &servicemonitor.Config{
Name: "local-kube-state-metrics-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
JobName: "local-kube-state-metrics",
MonitorMatchingLabels: monitorMatchingLabels,
ServiceMatchingLabels: serviceMatchingLabels,
}
}
func getIngestionServiceMonitor(monitorMatchingLabels, serviceMatchingLabels map[string]string) *servicemonitor.Config {
relabelings := []*servicemonitor.ConfigRelabeling{{
Action: "labelkeep",
Regex: "(__.+|job|node|namespace|daemonset|statefulset|deployment|condition|status)",
}}
metricRelabelings := []*servicemonitor.ConfigRelabeling{{
Action: "keep",
SourceLabels: []string{
"__name__",
"condition",
"status",
},
Regex: "kube_node_status_condition;Ready;true|(kube_deployment_status_replicas|kube_deployment_spec_replicas|kube_deployment_status_replicas_available|kube_statefulset_status_replicas_current|kube_statefulset_replicas|kube_statefulset_status_replicas_ready|kube_daemonset_status_current_number_scheduled|kube_daemonset_status_desired_number_scheduled|kube_daemonset_status_number_available);;",
}, {
Action: "replace",
SourceLabels: []string{
"daemonset",
"statefulset",
"deployment",
},
TargetLabel: "controller",
Regex: "(.*);(.*);(.*)",
Replacement: "${1}${2}${3}",
}, {
Action: "replace",
SourceLabels: []string{"__name__"},
TargetLabel: "__name__",
Replacement: "dist_${1}",
}, {
Action: "labelkeep",
Regex: "(__.+|job|node|namespace|controller)",
}}
endpoint := &servicemonitor.ConfigEndpoint{
Port: "http",
Path: "/metrics",
HonorLabels: true,
Relabelings: relabelings,
MetricRelabelings: metricRelabelings,
}
return &servicemonitor.Config{
Name: "ingestion-kube-state-metrics-servicemonitor",
Endpoints: []*servicemonitor.ConfigEndpoint{endpoint},
JobName: "ingestion-kube-state-metrics",
MonitorMatchingLabels: monitorMatchingLabels,
ServiceMatchingLabels: serviceMatchingLabels,
}
}
func GetServicemonitors(instanceName string) []*servicemonitor.Config {
appName := info.GetName()
monitorLabels := labels.GetMonitorLabels(instanceName, appName)
ls := labels.GetApplicationLabels(appName)
return []*servicemonitor.Config{
getLocalServiceMonitor(monitorLabels, ls),
getIngestionServiceMonitor(monitorLabels, ls),
}
}