Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions exporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ var (
dollarRe = regexp.MustCompile(`\_$`)
)

var prometheusizeCache = make(map[string]string)

// prometheusize renames metrics by replacing some prefixes with shorter names
// replace special chars to follow Prometheus metric naming rules and adds the
// exporter name prefix.
func prometheusize(s string) string {
if renamed, exists := prometheusizeCache[s]; exists {
return renamed
}
back := strings.Clone(s)

for _, pair := range prefixes {
if strings.HasPrefix(s, pair[0]+".") {
s = pair[1] + strings.TrimPrefix(s, pair[0])
Expand All @@ -180,6 +187,8 @@ func prometheusize(s string) string {
s = repeatedUnderscoresRe.ReplaceAllString(s, "_")
s = strings.TrimPrefix(s, "_")

prometheusizeCache[back] = strings.Clone(s)

return exporterPrefix + s
}

Expand Down
Loading