diff --git a/metrics/collector.go b/metrics/collector.go index 17664d07cfd..1df9d0fb22a 100644 --- a/metrics/collector.go +++ b/metrics/collector.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "strconv" + "strings" "github.com/VictoriaMetrics/metrics" ) @@ -84,15 +85,23 @@ func (c *collector) addTimer(name string, m *metrics.Summary) { } func (c *collector) writeGauge(name string, value interface{}) { - //c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, name)) + c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, stripLabels(name))) c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value)) } func (c *collector) writeCounter(name string, value interface{}) { - //c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name)) + c.buff.WriteString(fmt.Sprintf(typeCounterTpl, stripLabels(name))) c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value)) } +func stripLabels(name string) string { + if labelsIndex := strings.IndexByte(name, '{'); labelsIndex >= 0 { + return name[0:labelsIndex] + } + + return name +} + func (c *collector) writeSummaryCounter(name string, value interface{}) { name = name + "_count" c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value))