-
Notifications
You must be signed in to change notification settings - Fork 94
/
apicast_monitoring.go
159 lines (152 loc) · 5.14 KB
/
apicast_monitoring.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package component
import (
"fmt"
"github.com/3scale/3scale-operator/pkg/assets"
"github.com/3scale/3scale-operator/pkg/common"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
grafanav1alpha1 "github.com/integr8ly/grafana-operator/v3/pkg/apis/integreatly/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func (apicast *Apicast) ApicastProductionPodMonitor() *monitoringv1.PodMonitor {
return &monitoringv1.PodMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-production",
Labels: apicast.Options.CommonProductionLabels,
},
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{{
Port: "metrics",
Path: "/metrics",
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: apicast.Options.CommonProductionLabels,
},
},
}
}
func (apicast *Apicast) ApicastStagingPodMonitor() *monitoringv1.PodMonitor {
return &monitoringv1.PodMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-staging",
Labels: apicast.Options.CommonStagingLabels,
},
Spec: monitoringv1.PodMonitorSpec{
PodMetricsEndpoints: []monitoringv1.PodMetricsEndpoint{{
Port: "metrics",
Path: "/metrics",
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: apicast.Options.CommonStagingLabels,
},
},
}
}
func ApicastMainAppGrafanaDashboard(ns string) *grafanav1alpha1.GrafanaDashboard {
data := &struct {
Namespace string
}{
ns,
}
return &grafanav1alpha1.GrafanaDashboard{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-mainapp",
Labels: map[string]string{
"monitoring-key": common.MonitoringKey,
},
},
Spec: grafanav1alpha1.GrafanaDashboardSpec{
Json: assets.TemplateAsset("monitoring/apicast-grafana-dashboard-1.json.tpl", data),
Name: fmt.Sprintf("%s/apicast-grafana-dashboard-1.json", ns),
},
}
}
func ApicastServicesGrafanaDashboard(ns string) *grafanav1alpha1.GrafanaDashboard {
data := &struct {
Namespace string
}{
ns,
}
return &grafanav1alpha1.GrafanaDashboard{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-services",
Labels: map[string]string{
"monitoring-key": common.MonitoringKey,
},
},
Spec: grafanav1alpha1.GrafanaDashboardSpec{
Json: assets.TemplateAsset("monitoring/apicast-grafana-dashboard-2.json.tpl", data),
Name: fmt.Sprintf("%s/apicast-grafana-dashboard-2.json", ns),
},
}
}
func ApicastPrometheusRules(ns string) *monitoringv1.PrometheusRule {
return &monitoringv1.PrometheusRule{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast",
Labels: map[string]string{
"prometheus": "application-monitoring",
"role": "alert-rules",
},
},
Spec: monitoringv1.PrometheusRuleSpec{
Groups: []monitoringv1.RuleGroup{
{
Name: fmt.Sprintf("%s/apicast.rules", ns),
Rules: []monitoringv1.Rule{
{
Alert: "ThreescaleApicastJobDown",
Annotations: map[string]string{
"summary": "Job {{ $labels.job }} on {{ $labels.namespace }} is DOWN",
"description": "Job {{ $labels.job }} on {{ $labels.namespace }} is DOWN",
},
Expr: intstr.FromString(fmt.Sprintf(`up{job=~".*/apicast-production|.*/apicast-staging",namespace="%s"} == 0`, ns)),
For: "1m",
Labels: map[string]string{
"severity": "critical",
},
},
{
Alert: "ThreescaleApicastRequestTime",
Annotations: map[string]string{
"summary": "Request on instance {{ $labels.instance }} is taking more than one second to process the requests",
"description": "High number of request taking more than a second to be processed",
},
Expr: intstr.FromString(fmt.Sprintf(`sum(rate(total_response_time_seconds_bucket{namespace='%s', pod=~'apicast-production.*'}[1m])) - sum(rate(upstream_response_time_seconds_bucket{namespace='%s', pod=~'apicast-production.*'}[1m])) > 1`, ns, ns)),
For: "2m",
Labels: map[string]string{
"severity": "warning",
},
},
{
Alert: "ThreescaleApicastHttp4xxErrorRate",
Annotations: map[string]string{
"summary": "APICast high HTTP 4XX error rate (instance {{ $labels.instance }})",
"description": "The number of request with 4XX is bigger than the 5% of total request.",
},
Expr: intstr.FromString(fmt.Sprintf(`sum(rate(apicast_status{namespace='%s', status=~"^4.."}[1m])) / sum(rate(apicast_status{namespace='%s'}[1m])) * 100 > 5`, ns, ns)),
For: "5m",
Labels: map[string]string{
"severity": "critical",
},
},
{
Alert: "ThreescaleApicastLatencyHigh",
Annotations: map[string]string{
"summary": "APICast latency high (instance {{ $labels.instance }})",
"description": "APIcast p99 latency is higher than 5 seconds\n VALUE = {{ $value }}\n LABELS: {{ $labels }}",
},
Expr: intstr.FromString(fmt.Sprintf(`histogram_quantile(0.99, sum(rate(total_response_time_seconds_bucket{namespace='%s',}[30m])) by (le)) > 5`, ns)),
For: "5m",
Labels: map[string]string{
"severity": "warning",
},
},
},
},
},
},
}
}