Skip to content

Commit

Permalink
Code review + ensure histogram count is cumulative
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Mar 12, 2024
1 parent 80071de commit 6b8062c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions plugins/parsers/prometheusremotewrite/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,28 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
t = time.Unix(0, hp.Timestamp*1000000)
}

fields := make(map[string]interface{})
fields[metricName+"_sum"] = h.Sum
fields := map[string]any{
metricName + "_sum": h.Sum,
}
m := metric.New("prometheus_remote_write", tags, fields, t)
metrics = append(metrics, m)

fields = make(map[string]interface{})
fields[metricName+"_count"] = h.Count
fields = map[string]any{
metricName + "_count": h.Count,
}
m = metric.New("prometheus_remote_write", tags, fields, t)
metrics = append(metrics, m)

count := 0.0
iter := h.AllBucketIterator()
for iter.Next() {
bucket := iter.At()
fields = make(map[string]interface{}, 1)
fields[metricName] = bucket.Count

count = count + bucket.Count
fields = map[string]any{
metricName: count,
}

localTags := make(map[string]string, len(tags)+1)
localTags[metricName+"_le"] = fmt.Sprintf("%g", bucket.Upper)
for k, v := range tags {
Expand Down

0 comments on commit 6b8062c

Please sign in to comment.