Skip to content

Commit

Permalink
add timestamp info from the source
Browse files Browse the repository at this point in the history
  • Loading branch information
asiyani committed Dec 28, 2024
1 parent aefdc2d commit 8cc81fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func (ra *RemoteAggregator) processAndSend(metricFamily *dto.MetricFamily, ch ch
if ra.addPrefix != "" {
name = ra.addPrefix + name
}

// assuming all metrics of same family will have same timestamp
ct := time.Now()
if len(metricFamily.Metric) > 0 && metricFamily.Metric[0].TimestampMs != nil {
ct = time.UnixMilli(*metricFamily.Metric[0].TimestampMs)
}
aggregatedLabels, aggregatedValue := aggregateMetrics(metricFamily.Metric, ra.aggregateWithOutLabels)

for key, value := range aggregatedValue {
Expand All @@ -155,7 +159,7 @@ func (ra *RemoteAggregator) processAndSend(metricFamily *dto.MetricFamily, ch ch
continue
}

ch <- promMetric
ch <- prometheus.NewMetricWithTimestamp(ct, promMetric)
}
}

Expand Down

0 comments on commit 8cc81fc

Please sign in to comment.