-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
126 lines (112 loc) · 3.52 KB
/
metrics.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
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
v1 "k8s.io/api/core/v1"
)
var (
k8sNormalEvents = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "event",
Subsystem: "normal",
Name: "k8s",
Help: "Exports kubernetes normal events count.",
},
[]string{
"namespace",
"reason",
"kind",
"source_host",
"source_component",
},
)
k8sSummaryEvents = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "event",
Subsystem: "summary",
Name: "k8s",
Help: "Exports summary of k8s events count.",
},
[]string{
"namespace",
"reason",
"kind",
"type",
},
)
k8sWarningEvents = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "event",
Subsystem: "warning",
Name: "k8s",
Help: "Exports kubernetes warning events count.",
},
[]string{
"namespace",
"reason",
"kind",
"source_host",
"source_component",
"message",
},
)
)
func init() {
prometheus.MustRegister(k8sNormalEvents)
prometheus.MustRegister(k8sWarningEvents)
prometheus.MustRegister(k8sSummaryEvents)
}
// IncSummaryEvent parses and increases an event counter with corresponding labels.
func IncSummaryEvent(event *v1.Event) {
k8sSummaryEvents.WithLabelValues(
event.Namespace, // namespace
event.Reason, // reason
event.InvolvedObject.Kind, // kind
event.Type, // type
).Inc()
}
// IncNormalEvent parses and increases an event counter with corresponding labels.
func IncNormalEvent(event *v1.Event) {
k8sNormalEvents.WithLabelValues(
event.Namespace, // namespace
event.Reason, // reason
event.InvolvedObject.Kind, // kind
event.Source.Host, // source_host
event.Source.Component, // source_component
).Inc()
}
// IncWarningEvent parses and increases an event counter with corresponding labels.
func IncWarningEvent(event *v1.Event) {
m := ""
if event.Reason == "FailedMount" {
switch {
case strings.Contains(event.Message, "timeout expired waiting for volumes to attach or mount"):
m = "timeout expired waiting for volumes to attach or mount"
case strings.Contains(event.Message, "rpc error: code = DeadlineExceeded desc = context deadline exceeded"):
m = "rpc error: code = DeadlineExceeded desc = context deadline exceeded"
case strings.Contains(event.Message, "volumeattachments.storage.k8s.io"):
m = "volumeattachments not found"
case strings.Contains(event.Message, ": secret") || strings.Contains(event.Message, ": configmap"):
m = "secret or configmap error"
}
}
if event.Reason == "FailedAttachVolume" {
switch {
case strings.Contains(event.Message, "is attached to a different instance"):
m = "is attached to a different instance"
case strings.Contains(event.Message, "Volume is already used by pod"):
m = "Volume is already used by pod"
case strings.Contains(event.Message, "Volume is already exclusively attached to one node"):
m = "Volume is already exclusively attached to one node"
case strings.Contains(event.Message, "attachment timeout for volume"):
m = "attachment timeout"
case strings.Contains(event.Message, "status must be available or downloading"):
m = "status must be available or downloading"
}
}
k8sWarningEvents.WithLabelValues(
event.Namespace, // namespace
event.Reason, // reason
event.InvolvedObject.Kind, // kind
event.Source.Host, // source_host
event.Source.Component, // source_component
m, // message
).Inc()
}