Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit dd23b3c

Browse files
committed
Send trend sum as metric
Signed-off-by: Pablo Chacin <[email protected]>
1 parent 48bf738 commit dd23b3c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/remotewrite/prometheus.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ func (pm *PrometheusMapping) MapTrend(ms *metricsStorage, sample metrics.Sample,
7676

7777
// Prometheus metric system does not support Trend so this mapping will
7878
// store a counter for the number of reported values and gauges to keep
79-
// track of aggregated values.
79+
// track of aggregated values. Also store a sum of the values to allow
80+
// the calculation of moving averages.
8081
// TODO: when Prometheus implements support for sparse histograms, re-visit this implementation
8182

8283
s := metric.Sink.(*metrics.TrendSink)
8384
aggr := map[string]float64{
8485
"count": float64(s.Count),
86+
"sum": s.Sum,
8587
"min": s.Min,
8688
"max": s.Max,
8789
"avg": s.Avg,
@@ -103,6 +105,18 @@ func (pm *PrometheusMapping) MapTrend(ms *metricsStorage, sample metrics.Sample,
103105
},
104106
},
105107
},
108+
{
109+
Labels: append(labels, prompb.Label{
110+
Name: "__name__",
111+
Value: fmt.Sprintf("%s%s_sum", defaultMetricPrefix, sample.Metric.Name),
112+
}),
113+
Samples: []prompb.Sample{
114+
{
115+
Value: aggr["sum"],
116+
Timestamp: timestamp.FromTime(sample.Time),
117+
},
118+
},
119+
},
106120
{
107121
Labels: append(labels, prompb.Label{
108122
Name: "__name__",

0 commit comments

Comments
 (0)