forked from prometheus-community/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes.go
125 lines (110 loc) · 3.25 KB
/
kubernetes.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
package main
import (
"encoding/json"
"fmt"
"regexp"
)
var (
apiNameRegexp = regexp.MustCompile(`mmkubernetes\((\S+)\)`)
)
type kubernetes struct {
Name string `json:"name"`
Url string
RecordSeen int64 `json:"recordseen"`
NamespaceMetaSuccess int64 `json:"namespacemetadatasuccess"`
NamespaceMetaNotFound int64 `json:"namespacemetadatanotfound"`
NamespaceMetaBusy int64 `json:"namespacemetadatabusy"`
NamespaceMetaError int64 `json:"namespacemetadataerror"`
PodMetaSuccess int64 `json:"podmetadatasuccess"`
PodMetaNotFound int64 `json:"podmetadatanotfound"`
PodMetaBusy int64 `json:"podmetadatabusy"`
PodMetaError int64 `json:"podmetadataerror"`
}
func newKubernetesFromJSON(b []byte) (*kubernetes, error) {
var pstat kubernetes
err := json.Unmarshal(b, &pstat)
if err != nil {
return nil, fmt.Errorf("failed to decode kubernetes stat `%v`: %v", string(b), err)
}
matches := apiNameRegexp.FindSubmatch([]byte(pstat.Name))
if matches != nil {
pstat.Url = string(matches[1])
}
return &pstat, nil
}
func (k *kubernetes) toPoints() []*point {
points := make([]*point, 9)
points[0] = &point{
Name: "kubernetes_namespace_metadata_success_total",
Type: counter,
Value: k.NamespaceMetaSuccess,
Description: "successful fetches of namespace metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[1] = &point{
Name: "kubernetes_namespace_metadata_notfound_total",
Type: counter,
Value: k.NamespaceMetaNotFound,
Description: "notfound fetches of namespace metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[2] = &point{
Name: "kubernetes_namespace_metadata_busy_total",
Type: counter,
Value: k.NamespaceMetaBusy,
Description: "busy fetches of namespace metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[3] = &point{
Name: "kubernetes_namespace_metadata_error_total",
Type: counter,
Value: k.NamespaceMetaError,
Description: "error fetches of namespace metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[4] = &point{
Name: "kubernetes_pod_metadata_success_total",
Type: counter,
Value: k.PodMetaSuccess,
Description: "successful fetches of pod metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[5] = &point{
Name: "kubernetes_pod_metadata_notfound_total",
Type: counter,
Value: k.PodMetaNotFound,
Description: "notfound fetches of pod metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[6] = &point{
Name: "kubernetes_pod_metadata_busy_total",
Type: counter,
Value: k.PodMetaBusy,
Description: "busy fetches of pod metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[7] = &point{
Name: "kubernetes_pod_metadata_error_total",
Type: counter,
Value: k.PodMetaError,
Description: "error fetches of pod metadata",
LabelName: "url",
LabelValue: k.Url,
}
points[8] = &point{
Name: "kubernetes_record_seen_total",
Type: counter,
Value: k.RecordSeen,
Description: "records fetched from the api",
LabelName: "url",
LabelValue: k.Url,
}
return points
}