[fix] name_prefix invalid to prometheus sample
This commit is contained in:
parent
04fe1eb704
commit
efdbf5c5e6
|
@ -3,6 +3,7 @@ package prometheus
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flashcat.cloud/categraf/pkg/conv"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
@ -83,8 +84,7 @@ func (p *Parser) Parse(buf []byte, slist *list.SafeList) error {
|
|||
} else if mf.GetType() == dto.MetricType_HISTOGRAM {
|
||||
p.handleHistogram(m, tags, metricName, slist)
|
||||
} else {
|
||||
fields := getNameAndValue(m, metricName)
|
||||
inputs.PushSamples(slist, fields, tags)
|
||||
p.handleSample(m, tags, metricName, slist)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,17 @@ func (p *Parser) handleHistogram(m *dto.Metric, tags map[string]string, metricNa
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Parser) handleSample(m *dto.Metric, tags map[string]string, metricName string, slist *list.SafeList) {
|
||||
fields := getNameAndValue(m, metricName)
|
||||
for metric, value := range fields {
|
||||
floatValue, err := conv.ToFloat64(value)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
slist.PushFront(inputs.NewSample(prom.BuildMetric(p.NamePrefix, metric, ""), floatValue, tags))
|
||||
}
|
||||
}
|
||||
|
||||
// Get labels from metric
|
||||
func (p *Parser) makeLabels(m *dto.Metric) map[string]string {
|
||||
result := map[string]string{}
|
||||
|
|
Loading…
Reference in New Issue