-
Notifications
You must be signed in to change notification settings - Fork 35
/
utils.go
53 lines (44 loc) · 1.08 KB
/
utils.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
package collectors
import (
"regexp"
"time"
"github.com/prometheus/client_golang/prometheus"
)
var (
resyncPeriod = 5 * time.Minute
ScrapeErrorTotalMetric = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "ksm_scrape_error_total",
Help: "Total scrape errors encountered when scraping a resource",
},
[]string{"resource"},
)
ResourcesPerScrapeMetric = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "ksm_resources_per_scrape",
Help: "Number of resources returned per scrape",
},
[]string{"resource"},
)
invalidLabelCharRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
)
func boolFloat64(b bool) float64 {
if b {
return 1
}
return 0
}
func kubeLabelsToPrometheusLabels(labels map[string]string) ([]string, []string) {
labelKeys := make([]string, len(labels))
labelValues := make([]string, len(labels))
i := 0
for k, v := range labels {
labelKeys[i] = "label_" + sanitizeLabelName(k)
labelValues[i] = v
i++
}
return labelKeys, labelValues
}
func sanitizeLabelName(s string) string {
return invalidLabelCharRE.ReplaceAllString(s, "_")
}