Skip to content

Commit

Permalink
Merge pull request #64 from kongfei605/prom_inputs
Browse files Browse the repository at this point in the history
[fix] name_prefix invalid to prometheus sample
  • Loading branch information
kongfei605 authored Jun 30, 2022
2 parents 9cc075d + a5872ea commit 3e292e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 1 addition & 5 deletions inputs/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ func NewSamples(fields map[string]interface{}, labels ...map[string]string) []*t

func PushSamples(slist *list.SafeList, fields map[string]interface{}, labels ...map[string]string) {
for metric, value := range fields {
floatValue, err := conv.ToFloat64(value)
if err != nil {
continue
}
slist.PushFront(NewSample(metric, floatValue, labels...))
slist.PushFront(NewSample(metric, value, labels...))
}
}
10 changes: 8 additions & 2 deletions parser/prometheus/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,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.handleGaugeCounter(m, tags, metricName, slist)
}
}
}
Expand Down Expand Up @@ -113,6 +112,13 @@ func (p *Parser) handleHistogram(m *dto.Metric, tags map[string]string, metricNa
}
}

func (p *Parser) handleGaugeCounter(m *dto.Metric, tags map[string]string, metricName string, slist *list.SafeList) {
fields := getNameAndValue(m, metricName)
for metric, value := range fields {
slist.PushFront(inputs.NewSample(prom.BuildMetric(p.NamePrefix, metric, ""), value, tags))
}
}

// Get labels from metric
func (p *Parser) makeLabels(m *dto.Metric) map[string]string {
result := map[string]string{}
Expand Down

0 comments on commit 3e292e1

Please sign in to comment.